欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

list和dict的表示

程序员文章站 2022-04-28 20:09:21
...

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