** How to make a dictionary ** {Key 1: Value 1, Key 2: Value 2} Note that the list and parentheses {} are different
fruits = {"apple":"Apple" , "banana":"banana" , "strawberry":"Strawberry"}
output Dictionary [key] Pay attention to the parentheses [] when outputting
fruits = {"apple":"Apple" , "banana":"banana" , "strawberry":"Strawberry"}
print("apple" + fruits["apple"] + "is")
Output result apple is an apple
** Element update ** Dictionary [key] = value
fruits = {"apple":"Apple" , "banana":"banana" , "strawberry":"Strawberry"}
fruits["banana"] = "Banana"
** Add element ** Dictionary [new key] = value
fruits = {"apple":"Apple" , "banana":"banana" , "strawberry":"Strawberry"}
fruits["kiwi"] = "Kiwi"
Recommended Posts