In this tutorial, you will learn about the contains in python. In Python, the in keyword is used to check if a value exists within a sequence, such as a list, tuple, string, or dictionary. in is used to check if a value exists in the specified data structure. If the value exists, the condition evaluates to True, otherwise it evaluates to False.
Contains in python
The _contains_() method in Python checks if a string contains a specific substring and returns True if it does and False if it doesn’t. It is case sensitive, meaning that it treats uppercase and lowercase letters as different characters.
a = 'xyz' print('a contains x =', a.__contains__('x')) print('a contains B =', a.__contains__('B')) print('a contains T =', a.__contains__('T'))
output:
a contains x = True
a contains B = False
a contains T = False