Python Tuple List Dictionary

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'}

原文地址:https://www.cnblogs.com/zhonghan/p/3188201.html