Ice*_*ant 7 python string substring
我想检查变量是否在末尾包含子字符串.
例如:
text = 'lord_of_pizzas_DFG'
if ???:
print('You shall pass')
else:
print('You shall not pass')
Run Code Online (Sandbox Code Playgroud)
我想知道如何检查"DFG"是否在字符串的末尾.我写什么而不是???让代码打印"你应该通过"?
Pad*_*ham 25
使用 str.endswith
text = 'lord_of_pizzas_DFG'
if text.endswith("DFG"):
print('You shall pass')
else:
print('You shall not pass')
Run Code Online (Sandbox Code Playgroud)