Getting the python vessel parsed

A. The four general list, set, tuple, dict complex data type called containers, which are open in the stack is used to store a large amount python provides a data structure of the data.
Two list (list):. Collection of data items in accordance with certain linear sequence, arrayed, is a linear list, a doubly linked list is based on the underlying python achieved. By a large number of nodes, each node may store data. So the list can store large amounts of data
1.python how to use the list, definition list:

①调用系统的一个全局函数list()

a = list () # Create an empty list
Here Insert Picture Description
a = list ([n1, n2 , n3 ... nn]), and creates a list of assignments
Here Insert Picture Description
② features may be utilized weakly typed language data to create a list of
b = [1,2,3 , 4,5]
Here Insert Picture Description
2. access list element
by subscripts accessing; (index from 0, subscript attention not out of range)

赋值:列表[下标] = 新值

Here Insert Picture Description
3. traversing element

for 变量 in 容器;
while循环:    index = 0  
				    while index < len(a) :
							print(a[index])
							Index += 1

4. The length of the list of questions:

全局函数len  len(列表名)

The list is the essence of an object: to expand the list, python list provides a number of methods to call to complete the desired function.
Here Insert Picture Description
The list of common methods:

1>.append:能够在列表末尾添加一个新的元素
2>.clear:会清除列表中的所有元素
3>.copy:复制列表(浅拷贝)

Copy and assignment difference: Copy will further open up the heap memory used to store a copy out of the list, the list and the original list are not synchronized; and the list and the original list assignment synchronization;

4>.count:返回某个数字的重复次数(统计某个元素在列表中的个数)

5>.index:查询(返回)元素在列表中第一次出现的下标位置,如果列表中不存在该元素,则抛出异常
6>.insert:指定要插入的元素的位置,eg:a.insert(2,"xiaozhan")
7>.remove:移除,移除的是对应的元素值,如果列表中不存在该元素,      则抛出异常
8>.pop:通过下标移除元素,默认没有下标的话,移除的是最后一个元素
9>.reverse:倒叙,反转元素的顺序
10>.sort:排序,(主要针对数据)按照数值大小排序
11>.extend:扩展,a.extend(b),合并列表

Three set (SET)
. 1> Definition:

使用全局函数 set()

S = set ({1,3,5,9,5}) ( used in python "{}" SET is not necessarily defined, there may be a dictionary, want to be SET, should write the value inside {})
Here Insert Picture Description
2> set of characteristics:

元素唯一,且元素无序,所以不能用下标去访问

3> set of common methods:

①add:在集合末尾添加元素
②clear:清除
③difference:求差集
④intersection:求交集
⑤union:并集
⑥pop:随机移除
⑦remove:移除元素
⑧discard:集合中有要移除的元素,则移除,没有移除的元素,则没有变化,不报错

Quad (tuple):. Indicates a fixed, constant values (immutable type), similarly the constant
1> is defined:

使用()表示   t = tuple(()),

Note: a = (), type ( a) is a tuple, the method of a = (1), type ( a) = int, to solve this problem are: a = (100,) because the python interpreter tuple treated as a number () is the mathematical meanings
Here Insert Picture Description
2> conventional method

  count ,index

Note: tuples are immutable type, the well defined mean value tuple, then can not be modified, however, if the elements of the tuple is a variable type, the tuple is variable eg: t = (1 2,3,6, [1,3,6,8]), the subscript of the element 4 is a list, a variable,, t [4] = [1,2,36,8,52 ]
five dictionaries (): structure: two-dimensional table, key must be a string, values may be any type
1> is defined:

d1 = {}     d1 = dict() d2 = dict({"name":"zhao","age":17})

Here Insert Picture Description
2> Access:
Here Insert Picture Description
D2 [ "name"], is determined by a key value, when the same key, overwrite the previous value; if the key does not exist, then the new key
3> common methods:

①get:通过key或者key对应的值,如果没有这个key,则返回none,表示没有这个值
②keys:返回所有的key
③values:返回所有的值
④items:成对返回键值对
⑥pop:通过key,删除对应的键值对,注意:如果该键值对不存在,则抛出异常
⑦popitem:按照后进先出(LIFO)的方法去移除键值对,没有参数。

(LIFO: LIFO storage means assumes after the first of inventories, costs of inventories calculated accordingly when using the method of LIFO, each batch sent cost of inventory, warehousing inventories last batch. unit prices, issue number if that number exceeds the number of the last batch of inventory warehousing, followed by the number of excess storage unit price calculation).
six dictionary iteration:
1> key to iterate
Here Insert Picture DescriptionHere Insert Picture Description

①for  k in d2 :                     
	Print(k)
②for k in d2.keys():
	Print(k,d2[k])

2> The value iterate
Here Insert Picture Description

for k in d2.values():
	Print(k)

3> of key / value iteration together
Here Insert Picture Description

for (k,v) in d2.items() :
	Print(k,v)
Published 17 original articles · won praise 2 · Views 371

Guess you like

Origin blog.csdn.net/qq_44487069/article/details/104427921