Python Check In String
Check In String
To check if a certain phrase or character is present in a string, we can use the keywords
in
or not in
.
Example
Check if the phrase "ain" is present in the following text:
txt = "The rain in Spain stays mainly in the plain"
x = "ain" in txt
print(x)
Try it Yourself »
Example
Check if the phrase "ain" is NOT present in the following text:
txt = "The rain in Spain stays mainly in the plain"
x = "ain"
not in txt
print(x)
Try it Yourself »
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.