Data Type: numbers, strings, lists, tuples, dictionaries

Data Type: numbers, strings, lists, tuples, dictionaries
 
1, numbers: int (range: -2147483648,2147483647), Long (i.e., the range exceeding the foregoing long integer), a float, Complex
a = 123 (int type)
a = 123L (long type)
a = 123.0 (float type)
a = 123.1j (complex type)
2, the string: a = 'qwert'
A random value a [0]
Slice values ​​a [1: 4] Output wer a [: 4] Output qwer a [2:] Output ert
Step values ​​a [:: 2] Output qet
Reverse value a [-1] t output
3. List
List with  []  identified python is the most common complex data type. Orderly and can be secondary assignment
It supports character, numeric, string or even contain a list (ie, nested).
Add a list of values: list.append () to modify a list of values: list [0] = "q" value list Delete: lis.remove (list [0]) or del (list [0])
Slice values: L [0: 3] before taking the three elements of the list
4, tuples
Tuple identified by "()." Internal element separated by commas. But the tuple is not a secondary assignment , the equivalent of read-only list.
The list is an ordered collection of objects, you can take the value of the index and the front way
Tuple is only a definition of the element: a (1,)
5, dictionaries
Dictionaries with "{}" logo. A dictionary index (key) value and a value corresponding to its composition.
A dictionary is unordered collection of objects.
增加值:直接增加dict['a'] = "q" 删除:del(dict['a']) 清空字典内容:dict.clear() 删除整个字典:del(dict)

Guess you like

Origin www.cnblogs.com/zhaozhenqiu/p/12098015.html