Pythonでのタプル内要素の存在確認
リスト内に特定の要素が存在するかどうかは、
演算子inを使用して確認できます:
tpl = ('a', 'b' 'c')
res = 'a' in tpl
print(res) # Trueを出力します
要素が存在しないことを確認するには、
演算子not inを使用する必要があります:
tpl = ('a', 'b' 'c')
res = 'a' not in tpl
print(res) # Falseを出力します
以下のタプルが与えられます:
tpl = (2, 4, 6, 10)
この中に数字8が含まれているかどうかを確認してください。
以下のタプルが与えられます:
tpl = ('abc', 'def')
この中に文字列'd'が含まれているかどうかを確認してください。
以下のコードが与えられます:
tpl = ('1', '2', '3')
res = 1 not in tpl
print(res)
コンソールに何が出力されるか答えてください。
以下のコードが与えられます:
tpl1 = ('ac', '3', 4, 'bd', 5)
tpl2 = (1, 2, 3)
res1 = 4 in tpl1
res2 = 2 not in tpl2
print(res1)
print(res2)
コンソールに何が出力されるか答えてください。