Introduction to basic concepts of Python and basic concepts of python
1. Introduction to Python
1.1 advantages of Python
Python is an interpreted, object-oriented, and advanced programming language with dynamic semantics;
Simple, easy to learn, free of charge;
High-level Language: when writing a program in Python, you do not need to consider the underlying details such as how to manage the memory used by your program;
Portability: due to its open-source nature, Python has been transplanted on many platforms. Open-source Python is almost applicable to various platforms.
Description: a program written in Python does not need to be compiled into binary code. It can be run directly from the source code. Inside the computer, the Python interpreter converts the source code into an intermediate form called bytecode, and then translates it into the machine language used by the computer and runs it.
Object-oriented: Python supports both process-oriented and object-oriented programming.
1.2 disadvantages of Python:
Slow Running Speed: Although Python runs faster than Java, there is still no comparison with the language to be compiled. If there is a speed requirement, it is best to use C ++ to rewrite the key part.
The second disadvantage is that the Code cannot be encrypted. If you want to release your Python program, the source code is actually released. This is different from the C language. The C language does not need to release the source code, but only requires the compiled machine code (that is, youWindowsFile. It is impossible to roll out the C code from the machine code. Therefore, all compiled languages do not have this problem, while the interpreted language must publish the source code.
1.3 Python functions:
What can I do with Python? You can perform routine tasks, such as automatically backing up your MP3 file. You can create websites. many well-known websites, including YouTube, are written in Python. You can also play the background of online games, many online games are developed in Python at the backend.
Of course, Python cannot do things, such as writingOperating System, Which can only be written in C language.Mobile phoneApplications can only use Swift/Objective-C (for iPhone) and Java (for iPhone)Android); Write 3D games, preferably C or C ++
2. Common Python Data Structures
2.1 list
List: the most frequently used data type in Python. The list can implement the data structure of most collection classes. It supports characters, numbers, strings, and even lists (nesting)
The list is identified by [] and is the most common Composite data type in Python.
To split values in the list, you can use the variable [header subscript; tail subscript] to extract the corresponding list. The default value starts from 0 to-1 on the right index, the subscript can be null to indicate the channel header or tail.
The plus sign (+) is the List link operator, and the asterisk (*) is a repeated operation.
2.2 tuples
Tuples are another data type, similar to List.
The tuples are identified. The element value cannot be updated, which is equivalent to the read-only list.
2.3 dictionary
A dictionary is the best built-in data structure type in Python except the list. A list is an ordered object structure, and a dictionary is an unordered object set.
The difference between the two is that the elements in the dictionary are accessed by keys, rather than by offset.
The dictionary is identified. A dictionary consists of an index (key) and its corresponding value (value.
2.4 index and sharding
Index: all the elements in the list or tuples are numbered-increasing from 0. These elements can be accessed by numbers separately. For example
You can obtain elements through indexes. All lists or tuples can be indexed in this way. When a negative index is used, the number starts from the last element in the list. The first element is-1, and the second element is-2. The number increases sequentially from the right to the left absolute value according to the negative value.
Sharding: similar to accessing a single element through an index, you can use the sharding operation to access elements in a moving range. Shards are implemented using two indexes separated by colons:
The implementation of the sharding operation requires two indexes as the boundary. The 1st indexes are contained in the shard, while the 2nd indexes are not included in the shard.
2.5 digits
Python supports five basic numeric types, three of which are integer types.
Int (signed integer)
Long (long integer)
Bool (Boolean)
Float (floating point value)
Complex (plural)