如何在python中编写IS NOT for string .endswith



如何用python编写类似!(str.endswith())的东西我的意思是我想检查如果字符串不是结束的东西。我的代码是

if text == text. upper():   and text.endswith("."):

但是我想把IS NOT放在and之后写

if text == text. upper():   and not text.endswith("."):

if text == text. upper():   and not(text.endswith(".")):

给出无效语法

你有一个额外的冒号:

if text == text. upper():   and not text.endswith("."):
#                       ^

删除它,你的代码应该可以正常工作:

if text == text.upper() and not text.endswith("."):

您可以使用not

if not str.endswith():

你的代码可以修改为:

if text == text.upper() and not text.endswith("."):

可以直接使用not()调度器:

not(str.endswith())

编辑:像这样:

if text == text. upper() and not(text.endswith(".")):
    do stuff

if text == text. upper() and not(text.endswith(".")):
   do studff

最新更新