1. Python object type:
(1) List: a = [1, 2, 4]
(2) dictionary: Key-value pair a = {'A': '1', 'B': '2 '}
(3) tuples: they are basically a list that cannot be changed. Just like a list, tuples are sequences, but they are unchangeable.
T = (1, 2, 3, 4) (PS: pay special attention to the difference with the list)
An unchangeable object cannot be changed after it is created.
A sequence is a collection of objects sorted by locations. Strings, lists, and metadata are all sequences in python.
2. Number:
In Python, numbers are not really object types, but a group of similar types.
3. Dynamic Data Types:
In Python, data types are automatically determined during running, rather than declared by code.
Step a = 3:
(1) create an object to represent value 3
(2) create a variable, if it has not been created
(3) connect variables with new object 3
The variable name is of no type and belongs to the object rather than the variable name. Therefore, the object requires two header information: (1) type identifier (2) Reference Counter
4. String:
If the letter r (in upper or lower case) appears before the first quotation mark of the string, the escape mechanism is disabled. Example: myfile = open (r 'C: \ new \ text.txt ', 'w ')
Triple quotation marks are often useful for writing multi-line characters. In addition, the triple quotation marks can be used as comments for block code.
Python defines the % binary operator for string operations. The % operator provides a concise method for writing multi-string replacement.
Rstrip () Clear the white space at the end of each line
5. List:
List is the most flexible ordered object type in python. The list can contain objects of any type: Numbers, strings, or even other lists. Unlike strings, the list isVariable objectThey all support remote modification operations, which can be achieved through the specified offset value and sharding, list method call, delete statement, and other methods. (PS: the strings are quotation marks, the list is brackets, the tuples are Parentheses, And the dictionary is braces.)
6. the dictionary is also a flexible data structure type in python. If the list is a combination of ordered objects, You can regard the dictionary as a disordered set, the main difference between them is that the elements in the dictionary are accessed by keys, rather than by offset.
Different from the list, each time a value is assigned to a new dictionary key, a new element is generated in the dictionary, which is different in the list, because python regards the offset that exceeds the end of the list as out-of-bounds and reports an error. To expand the list, you must use the append method or multipart assignment.
7. tuples:
Tuples are similar to strings, which are immutable. Similar to strings and lists, tuples are sequences and they support many of the same operations.
Similar to the list, tuples are better considered as arrays referenced by objects. Tuples direct to storage points of other objects, and the indexing speed of tuples is relatively fast.
To sort tuples, you must first convert them to a list (using the list function) to obtain the permission to call the sorting method and change them to a variable object.
The non-variability of tuples only applies to the top layer of the tuples, not the content. You can modify the list of tuples as usual.
Why does a list have tuples?
A: immutable tuples provide some integrity. In this way, you can ensure that the tuples are not modified by another reference in the program, and the list does not provide such a guarantee.
8. file:
9. copy and reference:
Most operations are referenced. If you do need to copy, you can specify the following requirements:
10. = and is
"=" Operator tests the equality of Values
"Is" expression to test object consistency
Python temporarily stores and reuses short strings for optimization.
11. python data type: