list和dict的表示

list列表用[ ]表示:

>>> things = ['a','b','c','d']
>>> print(things[1])
b
>>> things[1] = 'z'
>>> things
['a','z','c','d']

字典dict用{ }表示:

>>> stuff = {'name':'Zed', 'age':39, 'height': 6*12+2}
>>> print(stuff['age'])
Zed
>>> stuff['city'] = 'SF'
>>> print(stuff['city'])
SF

猜你喜欢

转载自blog.csdn.net/Poisson_SHAN/article/details/81561346