「Python」values()で辞書の値の存在を確認するサンプルコード

2020年12月7日

構文
指定値 in 辞書名.values()
サンプルコード

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("辞書の値の存在: ", '122' in cft.values())
print("辞書の値の存在: ", '56' in cft.values())
print("辞書の値の存在: ", 'Td' not in cft.values())
# coding: utf-8 #!/usr/bin/python3 cft = {'Taa': '122', 'Tbb': '344', 'Tcc': '566', 'Tdd': '777'} print("辞書の値の存在: ", '122' in cft.values()) print("辞書の値の存在: ", '56' in cft.values()) print("辞書の値の存在: ", 'Td' not in cft.values())
# coding: utf-8

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

print("辞書の値の存在: ", '122' in cft.values())

print("辞書の値の存在: ", '56' in cft.values())

print("辞書の値の存在: ", 'Td' not in cft.values())

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

Python

Posted by arkgame