Data types commonly used in Python:
Data composition: The data is composed of three parts, namely the identity (that is, memory address, you can use the ID function to view), type (can be viewed using the type function), numeric
There are several types of data commonly used in Python:
1.number Numeric type
2. Sequence-Includes: string, tuple, list
3. Dictionaries
4. Collection
Related operations for data types commonly used in Python
1. Number types include: int, float, long, plural, etc.
A numeric type is a data type that cannot be changed, that is, each time it is assigned, it will always open up a memory space, and can be determined by the ID () function to get the corresponding memory space.
2. Sequence: The function of index and slice can be used in sequence, but the value of string and tuple is also immutable, and the value in the list can be changed;
Str= ' tyuuu '
2.1 Common Ways to string:
2.1.1 Str[index]---index, for example: Str[0] It is a positive sort starting from 0, or it can be reversed from 1 onwards, i.e. str[4]=str[-1];
2.2.2 Common Index Descriptions
Str[:] to show all;
Str[0:] represents all after starting from 0;
Str[0:3] represents starting from 0 until 2, which does not contain 3;
Str[:3] represents starting from 0 until 2, which does not contain 3;
Str[0:3:2] means starting from 0 until 2, not including 3, and each step is 2;
Str[::2] represents all that starts from 0 until the end, and the number of steps is 2;
2.3.3 +: Two strings can be connected by ' + ', *n:n add Len () to find the function of string length, System function max (): The maximum value in the string, after the conversion by ASC code to compare; Min (): The minimum value in the string, which is compared by the ASC code; 2.3.4. String modification because the string is immutable, you cannot use the index, but you can use the Repleace function to change the substitution. At this point it creates a new object (a new memory space), and its original object does not change the
2.2 tuples, similar to string methods, index, slice, add, length, maximum, minimum, etc.
tup= (2,6, ' Yu ', 8, ' IOPL ')
2.3 list
list=[2,5, ' Ty ', 7 ', [6,7], ' Yui ']
2.3.1 List of common methods:
2.3.1.1 A significant difference between a list and a tuple and a string is that the list can be assigned by index, for example, list[3]= ' PPP '; The list can be added as an index;
2.3.1.2 The following is a list of the methods
List.append ()----Insert a value at the end of the list whose value cannot be a list;
List.insert (Index, ' ty ')---Inserts a specified value at the specified position in the list, The former is the position of the index, the latter is the corresponding value;
List.extend ()--------inserts a value at the end of the list, which can be extended by the list;
List.sort ()-------The list is sorted by size;
List.remove (' value ')-----removes the specified value from the list, value is an already present in the list, or an error occurs, or a value in the list can be deleted by the system function del (), for example, Del (list index). The function is a
List.resort () that is deleted by an index-----The list is sorted by size;
2.4 Dictionary: A dictionary is a data type of a key-value pair with the following structure:
dict={' name ': ' Zhang ', ' age ' : 34,3:45}----dict{key1:value1,key2:value2,,key3:value3,.......}
It is unordered and therefore cannot use an index, but it has a function like an index that can use Dict[name] to find an element; its key is immutable and his value can be arbitrarily changed, so key cannot use a list or dictionary;
2.4.1 dictionaries are commonly used in the following ways:
Dict.pop (' name ') #返回并删除该键值
Dict.clear () #删除字典的所有元素, the dictionary is still in, just an empty dictionary dictionary, the dictionary comes with a method
del (dict) # Delete the dictionary, that is, the dictionary no longer exists, the system public Function
Dict.get (7, ' value ') #取key the value of the =7 dictionary, and if the key value of key=7 does not exist, returns the custom value content;
Python data type