Created
April 30, 2020 13:20
-
-
Save ashitaka1963/f9e497dd1974727a1d37b0de41d4aae1 to your computer and use it in GitHub Desktop.
辞書型
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# {key1:value1,key2:value2,key3:value3} | |
# 宣言 | |
mydict = {"apple":1, "orange":2, "banana":3} | |
# キーから値を取得 | |
val = mydict["apple"] | |
print(val) # 1 | |
print(mydict) # {'apple': 1, 'orange': 2, 'banana': 3} | |
# 値を取得 | |
mydict["apple"] += 1 | |
print(mydict["apple"]) # 2 | |
# キーの存在チェック | |
if "apple" in mydict.keys(): | |
print('IN') # IN | |
else: | |
print('OUT') | |
# キーの一覧を出力 | |
for i in mydict: | |
print(i) | |
# apple | |
# orange | |
# banana |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment