Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想检查问号或点是否在单词的最后位置。所以做类似的事情:
if ".","?" in word[-1]:
或者:
if [".","?"] in word[-1]:
导致语法无效。这样做的正确方法是什么?(最好没有正则表达式)
对于这种特殊情况,您要检查结尾:
if word.endswith(('.','?')):
你把顺序倒过来了。
if word[-1] in ".?":
请参阅文档in中的操作员
in