# dict is comprised by many key/value pairs
# dict is variant, but its key is invariant
# list ( example_list = ['mouse', 'keypad'] ) can not be the key, because list is variant.
# tuple ( example_tuple = ('alice', 23) ) is comprised by many items, is invariant, so can be the key.
# "key in dict" can return a bool value, to judge the key is in the dict or not
# "del dict[key]" can delete the key/value pair in the dict
# len(example_dict) can get the length of the example_dict
slang_dict = {"yyds": "always be successful"}
slang_dict["mm"] = "beautiful woman"
slang_dict["sg"] = "handsome man"
slang_dict["ss"] = "my boy"
print(slang_dict)
inquery = input("pls input your inquery:")
if inquery in slang_dict:
print("the meaning of item " + inquery + " is:")
print(slang_dict[inquery])
else:
print("not find " + inquery + " in the dict!")
print("the length of the dict is:" + str(len(slang_dict)))
python入门 --- dict
最新推荐文章于 2024-05-19 23:31:32 发布