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"?
Use str.endswith
text = 'lord_of_pizzas_DFG'
if text.endswith("DFG"):
print('You shall pass')
else:
print('You shall not pass')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With