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