簡體   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