Python Standard data types
There are six standard data types:
1. Number (digital)
2, String (strings)
3, tuple (tuple)
4. List (lists)
5. Dict (dictionary)
6, sets (collection)
Python Data type classification
Variable data:
Dictionaries, lists
Immutable data:
Numbers, strings, tuples, collections
Python Data Type introduction number
Python3 supports float, int, complex, bool
There is only one type of int in Python3, representing a long integer, without python2 long
Example:
a,b,c,d = 1.1,1,1+3j,True
You can view it in type:
>>> map(lambda x:type(x),[1,1.1,1+3j,True])[<type ‘int‘>, <type ‘float‘>, <type ‘complex‘>, <type ‘bool‘>]
You can also use instance:
>>> isinstance(1.1,float)True
String strings
A string or series (string) is a string of characters consisting of numbers, letters, and underscores.
A string of characters consisting of letters, numbers, and underscores
It is the type of text that is represented in the programming language
Example:
定义字符串:>>>a = ‘stringtype‘取出字符串:>>>>>>a‘stringtype‘截取前5位字符:>>>a[0:5] 从0开始,但截止到5之前‘strin‘截取最后一位字符:>>>a[-1:]‘e‘
List
The list is assigned a value of "[]"
A list is one of the most frequently used data types.
The interception method can also be intercepted using "Start: End".
Example:
>>> data = [1,2,3,5,6,2,1,4]>>> data[0:2][1, 2]
Meta-group
The tuple is identified with a "()". The inner elements are separated by commas. However, tuples cannot be assigned two times, which is equivalent to a read-only list.
Example:
>>> a = (1,2,3,4,5)>>>>>> a[0:3](1, 2, 3)尝试改变,但是是失败的:>>> a[2] = 5Traceback (most recent call last): File "<stdin>", line 1, in <module>TypeError: ‘tuple‘ object does not support item assignment
Dictionary
A list is an ordered collection of objects, and a dictionary is an unordered collection of objects.
The difference between the two is that the elements in the dictionary are accessed by keys, not by offsets.
The dictionary is identified with "{}". A dictionary consists of an index (key) and a value corresponding to it.
Example:
>>> a = {‘a‘:‘b‘,‘c‘:‘d‘,‘b‘:‘a‘}>>> a{‘a‘: ‘b‘, ‘c‘: ‘d‘, ‘b‘: ‘a‘}也可以用dict函数赋值:>>> a = dict([(‘a‘,‘b‘)])>>> a{‘a‘: ‘b‘}
Create an empty dictionary using:
a = {}或a = dict()
Python Basic data type