In Python, a string is a sequence of characters or text that is enclosed with either single quotes (
' ') or double quotes (
'Theo' is a string. Whether the characters are enclosed in single quotes or double quotes, it is still the same string; in other words,
'Theo' is the same as
in statement is used to check if a character or sequence of characters is present in a string.
The return value of the
in keyword is either
# creating a string axiom = 'Nothing worth while ever is' # using the in keyword print('never' in axiom) print('ever' in axiom)
neveris present in the string we created.
everis present in the string we created.
in keyword can also be used in an
# creating a string axiom = 'Nothing worth while ever is' # using the if statement if 'ever' in axiom: print("True! The word 'ever' is present in the string.")
In the code above, we use the
in keyword to check if the word
'ever' is present in the string we created, and we get
True as the result.
View all Courses