Python字典的操作

lm_y發表於2017-08-24
dict1={'yangrong': ['23', 'IT'], 'xiaohei': ['22', 'dota']}
dict2={'yangrong': {'age': "23", 'job': "IT"}, 'xiaohei':{"'age':'22','job':'dota'"}}
dict3={'yangrong': ['23', 'IT'], 'xiaohei': ['22', 'dota']}
dict4 = {1 : 'apple', 2 : 'banana', 3 : 'orange'}
dict5 = {4 : 'apples', 5 : 'bananas', 6 : 'oranges'}

#dict4.update(dict1)#更新操作

print(dict1.items())
print(dict1.keys())
print(dict1.values())
print(len(dict1))
print(str(dict1))
print(dict1.clear())
print(str(dict1))
print(dict4.keys())
print(dict4.values())


seq = ('name', 'age', 'sex')
dictq = dict.fromkeys(seq, dict4.__len__())
print(dictq)

相關文章