w3resource

Python: Check whether a string contains all letters of the alphabet


Check if string has all alphabet letters.

Write a Python program to check whether a string contains all letters of the alphabet.

Python String Exercises: Check whether a string contains all letters of the alphabet

Sample Solution:

Python Code:

# Import the 'string' module to access the lowercase alphabet.
import string

# Create a set 'alphabet' containing all lowercase letters using 'string.ascii_lowercase'.
alphabet = set(string.ascii_lowercase)

# Define an input string.
input_string = 'The quick brown fox jumps over the lazy dog'

# Check if the set of lowercase characters in the input string contains all the letters of the alphabet.
# Print the result (True or False).
print(set(input_string.lower()) >= alphabet)

# Update the input string.
input_string = 'The quick brown fox jumps over the lazy cat'

# Check if the set of lowercase characters in the updated input string contains all the letters of the alphabet.
# Print the result (True or False).
print(set(input_string.lower()) >= alphabet) 

Sample Output:

True                                                                                                          
False                        

Flowchart:

Flowchart: Check whether a string contains all letters of the alphabet

For more Practice: Solve these Related Problems:

  • Write a Python program to determine if a string is a pangram, containing every letter of the English alphabet.
  • Write a Python program to use set operations to verify that all letters from 'a' to 'z' are present in a given string.
  • Write a Python program to convert a string to lowercase and check if its set of characters covers the alphabet.
  • Write a Python program to implement a function that returns True if the input string is a pangram, and False otherwise.

Go to:


Previous: Write a Python program to print the index of the character in a string.
Next: Write a Python program to convert a given string into a list of words.

Python Code Editor:

Contribute your code and comments through Disqus.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.