List
List list variable (support indexing), ordered ( in situ modification )
You need to store large amounts of data and require these data when ordered.
An index list, and a slicing step size and index are not the same character string, the list can be modified by an index, as the string can not be changed, if the index is also given by the modified
increase
append additional
insert Insert insert (position, Inserts) position: this position until a new content
extend iterative added
delete
remove delete elements by name
pop delete elements by index (default delete the last: "pop-up")
clear Clear List
del (del list name [index or slice or step])
change
Modified by index
By modifying sections: defaults in steps of 1, the item must be iterable, modify the content can be more or less
Modified by step: step 1 is not necessary correspond
check
for circulation and indexes, as well as a list of index names .index (element name) --- print display Index
Other methods:
- Find a list of index names .index (elements) by element
- Sort, the default is ascending list name .sort ()
- Descending list name .sort (reverse = True)
- Reverse, reverse the source data list name .reverse ()
- Artificial descending to ascending, then reversed
- Does not modify the source data is inverted lst1 = lst [:: - 1]
Tuple
Tuple tuple immutable, ordered tuple is an immutable list
Method tuple:
- 统计 count(元素名称)
- 获取索引 元组名.index(元素名称)
tu = (1,[]) * 3
print(tu) # (1, [], 1, [], 1, [])
tu[-1].append(10)
print(tu) # (1, [10], 1, [10], 1, [10])
# 列表在进行乘操作时,元素是共用的.元组同样如此