How to check if a string contains certain characters in Python

Checking if a string contains certain characters returns True if the string is composed of only the specified characters and False otherwise.

Solution for How to check if a string contains certain characters in Python : You can use all() to check if a string contains certain characters Use the list comprehension syntax character in list for character in string to return a list of booleans indicating whether each character in string is contained in list. Call all(matched_list) with matched_list as the result of the previous step to return True if every character in string is in list and False otherwise.


how-to-check-if-a-string-contains-certain-characters-in-python