如何在python中编写str.endswith不适用

如何在python中编写str.endswith不适用,python,Python,如何编写类似于的东西!(str.endswith())在python中 我的意思是我想检查字符串是否以某物结尾。 我的代码是 if text == text. upper(): and text.endswith("."): 但我想放的是不是后和 书写 或 给我无效语法您可以使用而不是 if not str.endswith(): 您的代码可以修改为: if text == text.upper() and not text.endswith("."): 您只需使用not()o操作器即

如何编写类似于
的东西!(str.endswith())
在python中 我的意思是我想检查字符串是否以某物结尾。 我的代码是

if text == text. upper():   and text.endswith("."):
但我想放的是不是后和 书写


给我无效语法

您可以使用
而不是

if not str.endswith():
您的代码可以修改为:

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

您只需使用
not()
o操作器即可:

not(str.endswith())
编辑: 像这样:


您有一个额外的冒号:

if text == text. upper():   and not text.endswith("."):
#                       ^
删除它,您的代码应该可以正常工作:

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

你试过了吗?
不是“foo”。endswith(“bar”)
不是一个运算符,不是一个函数。啊,的确如此。谢谢你的更正。无效语法伙计:(你是什么意思?嗯,不是在python2.7.3中,你在使用哪个版本?删除最后一个字符串,不带文本==如果不检查文本
if text == text. upper() and not(text.endswith(".")):
    do stuff
if text == text. upper() and not(text.endswith(".")):
   do studff
if text == text. upper():   and not text.endswith("."):
#                       ^
if text == text.upper() and not text.endswith("."):