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.
これはおそらくばかげた質問になるでしょうが、なぜこのコードはこのように動作するのでしょうか?
>>> test = ['aaa','bbb','ccc'] >>> if 'ddd' or 'eee' in test: ... print True ... True >>>
IF ステートメントの文字列がリストにないため、stdio には何も出力されないと予想していました。
何か不足していますか?
あなたのテストは
if 'ddd' in test or 'eee' in test:
あなたが現在持っているコードでは、「ddd」文字列はブール値として評価され、空ではないため、そのブール値はTrueです