The Python array also has an abnormal usage method, that is, it can be called without the order of parameters. It is helpful for us to learn how to create a Python array correctly, and we can also learn a lot of programming skills from it, for example, delegate and template methods. I hope you can study it together.
In ubuntu, it is a more necessary script engine, so it is necessary to learn about it. The article here is only intended for users who have certain programming basics, preferably those who are familiar with php or javascript, if you do not have any basic beginner, you are advised to find more detailed tutorials.
Python array variables do not need to be defined. Like php, It is loose than javascript, but it uses indentation as a paragraph identifier, as a person who is used to the C language style syntax, he may not be used to it at the beginning. However, I think it is actually quite normal and reasonable. Although Python is loose in process-oriented/object-oriented aspects, the general program is actually a main entry.
Then, other class libraries or functions are constantly called, so there is nothing wrong with indentation. On the one hand, this requires users to standardize code writing, and on the other hand, redundant {} is saved in reverse order {}. Compared with the C language style, Python has the following main syntax features:
In python, all variables are objects. arrays are actually a linked list and can be linked. For common data types, the definition and value assignment methods are the same. I will not introduce them here. For python strings, I will introduce them here.
Python uses ['] ["] To enclose strings with the same meaning. It also uses [\] to escape special characters. However, it has a special Syntax: ['''] It is used to enclose strings that are divided into multiple rows. It can also be used as its multi-row annotation, for example:
- #!/usr/bin/python
- #python source
- class python:
- def Hello(self):
- print 'Hello'
- def count(n):
- in=0
- while(in<=n):
- inin=in+1
- print in
-
- //buile by G++ or VC++
- //C++ Source
- #include <iostream>
- int main()
- {
- class python
- {
- public:
- void Hello(void)
- {
- cout<<"Hello"<<endl;
- }
- void count(int n)
- {
- int in=0;
- while(in<=n)
- {
- inin=in+1;
- cout<<in<<endl;
- }
- }
- };
- return 0;
- }
The python array is actually not an array, but a list object. If you want to refer to its usage, you can refer to the method of this object. It should be noted that the python array is actually a linked list. Therefore, after definition, you cannot append elements directly to the backend like php. Instead, you need to use the linked list operation method.
In the preceding example, if arr [2] = 'ccccccc' is used, the value of the third element can be changed, however, if you use arr [3] = 'ddddd' to add an element, the following error occurs: arr. append ('ddddd ') or arr. insert (any location, 'dddd') to add elements.
For multi-dimensional arrays, the definition is as follows: arr = [[] * 3. It defines: [[], [], [], you can also use arr = [[] for I in range (3)] for common operations such as arrays and strings, which will be described in the following chapter, here we will not list more usage methods.
The python array is actually not an array, but a list object. If you want to refer to its usage, you can refer to the method of this object. It should be noted that the python array is actually a linked list. Therefore, after definition, you cannot append elements directly to the backend like php. Instead, you need to use the linked list operation method.
In the preceding example, if arr [2] = 'ccccccc' is used, the value of the third element can be changed, however, if you use arr [3] = 'ddddd' to add an element, the following error occurs: arr. append ('ddddd ') or arr. insert (any location, 'dddd') to add elements.
For multi-dimensional arrays, the definition is as follows: arr = [[] * 3. It defines: [[], [], [], you can also use arr = [[] for I in range (3)] for common operations such as arrays and strings, which will be described in the following chapter, here we will not list more usage methods.
- Introduction to Python system files
- How to correctly use Python Functions
- Detailed introduction and analysis of Python build tools
- Advantages of Python in PythonAndroid
- How to Use the Python module to parse the configuration file?