To facilitate modification and maintenance, you can divide the program you want to operate into several modules. First, you must create a module, put the First-off Python script into a file. The file name is the module name.
The import Statement creates a new namespace that contains the names of all defined objects in the module. To access this namespace, use the module name as a prefix to use the objects in this module, as in the preceding example: div. divide ()
Python scripts and modules are all files ended with. py. How does the program determine whether a. py file is used as a script or a module? The key is a variable named _ name _. If its value is _ main __, it runs directly as a script; otherwise, it runs as a module.
The init _ function is executed every time a class is generated. self points to the Class Object and remembers that the first parameter of a class function (or method) "self" should not be forgotten to write.
1) the first letter of the naming rule class is capitalized.
2) Functions and variables should be in lowercase as much as possible, with underlines between words
3) The member variables starting with "single underline" in the class are called protection variables, meaning that only class objects and subclass objects can access these variables themselves;
4) The "Double underline" begins with a private member, which means that only the class object can access the data, and even the subclass object cannot access the data.
The founder of the Python script is Guido van rosum. In Amsterdam during the Christmas Day of 1989, Guido was determined to develop a new script interpreter to ease Christmas. As an inheritance of the ABC language. Select the meaning of Python) as the program name.
He is a fan of Monty Python flying circus. ABC is a teaching language designed by Guido. In Guido's opinion, ABC is a very elegant and powerful language designed specifically for non-professional programmers.
However, the ABC language is not successful. The reason is that Guido believes that it is not open. Guido is determined to avoid this error in Python. It is true that Python is well integrated with other languages such as C, C ++ and Java ). At the same time, he also wants to implement things that flash in ABC but have never been implemented.
In this way, Python was born in Guido. In fact, the first implementation is on a Mac machine. It can be said that Python was developed from ABC and was mainly influenced by another very beautiful and powerful language of Modula-3, designed for small groups. It also integrates the Unix shell and C habits.
Python is widely used in programming languages in many large-scale software development plans, such as Zope, Mnet, and BitTorrent. Google. It is generally considered that Python is an explanatory language, but this statement is incorrect. In fact, when a Python script is executed. the source code in the py file is compiled into the byte code bytecode of Python ).
Then, the compiled byte code is executed by Python Virtual Machine. The basic idea of this mechanism is consistent with that of Java and. NET. However, what is different between Python Virtual Machine and Java or. NET Virtual Machine is that Python Virtual Machine is a more advanced Virtual Machine.
The level here is not generally advanced, not to say that Python's Virtual Machine is better than Java or. NET is more powerful than Java or. NET, Python's Virtual Machine is far from the real Machine. Alternatively, Python Virtual Machine is a Virtual Machine with a higher abstraction level.
- 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?