Python 字典的创建赋值和动态扩展

>>> cleese={}
>>> palin=dict()
>>> type(cleese)
<class 'dict'>
>>> type(palin)
<class 'dict'>
>>> cleese['Name']='John Cleese'
>>> cleese['Occupations']=['actor','comedian','writer','film producer']
>>> palin={'name':'Michael Palin','Occupations':['comedian','actor','writer','tv']}
>>> palin['name']
'Michael Palin'
>>> cleese['Occupations'][-1]
'film producer'
>>> palin['Brithplace']="England"
>>> cleese['Birthplace']="US"
>>> palin
{'Occupations': ['comedian', 'actor', 'writer', 'tv'], 'name': 'Michael Palin', 'Brithplace': 'England'}
>>> cleese
{'Name': 'John Cleese', 'Occupations': ['actor', 'comedian', 'writer', 'film producer'], 'Birthplace': 'US'}
>>> 
原文地址:https://www.cnblogs.com/oskb/p/4848486.html