「Python」in演算子で辞書のキーを確認する方法

2020年12月7日

構文
キー名 in 辞書名
使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# coding: utf-8
#!/usr/bin/python3
cft = {'Taa': '122', 'Tbb': '344', 'Tcc': '566', 'Tdd': '777'}
print("辞書のキーの存在: ", 'Taa' in cft)
print("辞書のキーの存在: ", '122' in cft)
print("辞書のキーの存在: ", 'Td' not in cft)
# coding: utf-8 #!/usr/bin/python3 cft = {'Taa': '122', 'Tbb': '344', 'Tcc': '566', 'Tdd': '777'} print("辞書のキーの存在: ", 'Taa' in cft) print("辞書のキーの存在: ", '122' in cft) print("辞書のキーの存在: ", 'Td' not in cft)
# coding: utf-8

#!/usr/bin/python3
 
cft = {'Taa': '122', 'Tbb': '344', 'Tcc': '566', 'Tdd': '777'}

print("辞書のキーの存在: ", 'Taa' in cft)

print("辞書のキーの存在: ", '122' in cft)

print("辞書のキーの存在: ", 'Td' not in cft)

実行結果
>python 101.py
辞書のキーの存在: True
辞書のキーの存在: False
辞書のキーの存在: True

Python

Posted by arkgame