How to Check If a Certain Character Exists in a String in Python


In this example we will show how to check if a certain phrase or character is present in a string in Python.

Source Code

my_str = 'I love Python'

check = 'o' in my_str

print(check)

Output:

True
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments

How to Check If a Certain Character Exists in a String in Python


In this example, we will learn how to check if a certain phrase or character is NOT present in a string in Python.

Source Code

my_str = 'I love Python'

check = 'o' not in my_str

print(check)

Output:

False
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments