Python string __contains__() is an instance method that returns a boolean value True or False depending on whether the target string contains the specified substring.
This method is case-sensitive. Therefore, it returns false in the scenario, like a character instead of A character.
Some developers do not use these private methods in their code. They said that avoid using these private methods on production code.
Syntax
string.__contains__(substr)
Parameters
substr(required): It takes a substr.
Return value
It returns a boolean value i.e. True or False.
Visual Representation
Example 1: How does the String __contains__() Method work?
str = 'AppDividend'
print(str.__contains__('Div'))
Output
True
Example 2: Case sensitive
str = 'AppDividend'
print('AppDividend contains app =', str.__contains__('app'))
Output
AppDividend contains app = False
Example 3: Using __contains__() function with input()
strA = input('Please enter first input string\n')
strB = input('Please enter second input string\n')
print('First Input String Contains Second String? ', strA.__contains__(strB))
Output
Please enter first input string
AppDividend
Please enter second input string
dend
First Input String Contains Second String? True