36.
37.
38.
39.
40.
列表:
>>> things = ['a', 'b', 'c', 'd']
>>> print things[1]
b
>>> things[1] = 'z' #!!!!!竟有这种操作
>>> print things[1] #!!!!!
z
>>> print things
['a', 'z', 'c', 'd']
>>>
字典:
它和列表的区别是它的索引可以是任何类型
例
>>> haha={'a':1,'b':2,'c':3}
>>> print(haha['a'])
1
>>> print(haha['b'])
2
>>> print(haha['c'])
3
>>> haha['d']=4 # !!!添加字典元素
>>> print(haha['d'])
4
>>> print(haha)
{'b': 2, 'c': 3, 'd': 4, 'a': 1}
还可以有这样的操作:
>>> haha[1]='sb'
>>> haha[2]='SB'
>>> print(haha)
{1: 'sb', 2: 'SB', 'c': 3, 'b': 2, 'd': 4, 'a': 1}
字典的删除,关键字:del
>>> print(haha)
{1: 'sb', 2: 'SB', 'c': 3, 'b': 2, 'd': 4, 'a': 1}
>>> del haha['a']
>>> print(haha)
{1: 'sb', 2: 'SB', 'c': 3, 'b': 2, 'd': 4}
>>> del haha[1]
>>> print(haha)
{2: 'SB', 'c': 3, 'b': 2, 'd': 4}
>>> haha={'a':1,'b':2,'c':3}
>>> 'a' in haha
True