EN
Python - check if string contains character
0 points
In this article, we would like to show you how to check if string contains character in Python.
Quick solution:
xxxxxxxxxx
1
text = "ABC"
2
print("B" in text) # True
In this example, we check if B
character is present in the text
string using in
keyword.
xxxxxxxxxx
1
text = "ABC"
2
if "B" in text:
3
print("The 'B' character is present in the", text)
Output:
xxxxxxxxxx
1
The 'B' character is present in the ABC