【python】in演算子を使う場合の注意点

エラー内容

in演算子はint型を処理出来ない為、下記のように記述するとエラーになる。

3 in 9939939
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
TypeError: argument of type 'int' is not iterable

解決策

下記のように型を変更する必要がある。

str(3) in str(9939939)
True

または、下記のように、int型でもリストでまとめればエラーにならない。

1 in [1,2,3]
True

※備忘録※ in演算子は前に”not”を置いて”not in”といった使い方も出来る。