w3resource

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

Python String: Exercise-45 with Solution

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

Python Code Editor:

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.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/python-exercises/string/python-data-type-string-exercise-45.php