博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

Python Tuple List Dictionary

Posted on 2013-07-13 17:09  钟悍  阅读(181)  评论(0)    收藏  举报

Tuple  (元组)

t = (1, 2, 4, 2, 3)
print t.count(2)   # 2
print t.index(4)   # 2
print t[1:]          # (2, 4, 2, 3)

 

List

lst = [1, 2, 4, 2,4, 3]
print lst.count(2)   # 2
print lst.index(4)   # 3
print lst[1:]          # [2, 4, 2, 4, 3]
lst.append(5)
lst.remove(4)
print lst                # [1, 2, 2, 4, 3, 5]

 

 

Dictionary

dicto = {"a":"b"}
print dicto # {'a': 'b'}
dicto['b'] = "c"
print dicto # {'a': 'b', 'b': 'c'}
dicto['b'] = "d"
print dicto # {'a': 'b', 'b': 'd'}
del(dicto["a"])
print dicto #{'b': 'd'}