繁体   English   中英

检查字符串末尾是否包含子字符串

[英]Check if a string contains substring at the end

我想检查变量是否在末尾包含子字符串。

例如:

text = 'lord_of_pizzas_DFG'

if ???:
    print('You shall pass')
else:
    print('You shall not pass')

我想知道如何检查“DFG”是否在字符串的末尾。 我怎么写而不是??? 使代码打印“你应该通过”?

使用str.endswith

text = 'lord_of_pizzas_DFG'

if text.endswith("DFG"):
    print('You shall pass')
else:
    print('You shall not pass')

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM