Reputation: 181
I would like to check if a variable contains a substring at the end.
For example:
text = 'lord_of_pizzas_DFG'
if ???:
print('You shall pass')
else:
print('You shall not pass')
I want to know how to check if "DFG" is at the end of the string. What do I write instead of ???
to make the code print "You shall pass"?
Upvotes: 11
Views: 22059
Reputation: 180540
Use str.endswith
text = 'lord_of_pizzas_DFG'
if text.endswith("DFG"):
print('You shall pass')
else:
print('You shall not pass')
Upvotes: 38