In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "how Python works". In daily operation, I believe many people have doubts about how Python works. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts about "how Python works"! Next, please follow the editor to study!
Python was originally a project developed by Guido Van Rossum in its spare time and was first released in 1991. As a lingua franca, Python provides strong support for many companies such as Netflix and Instagram. In an interview, Guido compared Python with languages such as Java/Swift, saying that Java/Swift is a good choice for software developers who do their daily work, that is, programming, while Python is aimed at people whose daily work has nothing to do with software development, and they write code mainly to process data.
Python is an interpreted high-level general programming language with dynamic typing and garbage collection functions.
Interpretive language
When writing a program in C / C +, it must be compiled. Compilation is the conversion of human-understandable code into machine-understandable code, namely "machine code". Machine code is the basic form in which CPU can execute instructions directly. After successful compilation, the code generates an executable file. Execute this file, and the actions in the code will run step by step.
Although you also need to compile this step, in most cases, Python is an interpreted language, not a compiled language. Python code written in a .py file is first compiled into bytecode (discussed in more detail later), and then stored in .pyc or .pyo format.
Python converts source code to bytecode, unlike C + + to machine code. The bytecode is a low-level instruction set that can be executed by the interpreter. The Python interpreter is installed under the / usr/local/bin/python3.8 path in most PC. Bytecode instructions are executed on the virtual machine rather than on the CPU.
Why did you choose an interpretive language?
Interpretive language has a major advantage independent of the platform. As long as the Python bytecode and the virtual machine version are the same, Python bytecode can be executed on any platform (Windows,MacOS, etc.).
Another advantage of Python is dynamic typing. In statically typed languages such as C +, you must first declare variable types and check for all differences (such as adding strings and integers) at compile time. But in strongly typed languages like Python, checking the validity of variable types and actions performed is done by the interpreter.
The shortcomings of interpretive language
Dynamic typing gives code a lot of freedom, but at the same time increases the risk of the code, and is sometimes difficult to debug.
Python is often accused of being "slow". This statement is relative and controversial, but it is "slow" because the interpreter needs to do extra work to convert bytecode instructions into instructions that can be executed on the machine. A post on StackOverflow makes it easier to understand:
If you can talk to others in your native language, it is usually much faster than an interpreter to translate your language into other languages to make them understand.
What on earth is garbage collection?
In early programming languages, memory allocation was mainly manual. In many cases, when a variable is no longer used or referenced elsewhere in the program, it needs to be manually cleared from memory. The garbage collection bin does this work instead of manual work, and the space can be automatically released without any operation. There are two ways to manage memory:
The simplified way is to track the number of references to an object. When the number drops to 0, delete the object. This approach is called "reference counting". This feature cannot be disabled in Python.
The generate garbage Collection thread can work when the object references itself or when the two objects refer to each other. This can not be solved by traditional reference counting.
What is _ _ pycache__?
In personal projects or on GitHub, you may often see a folder named _ _ pycache__ created automatically.
/ folder-_ pycache_-preprocess.cpython-36.pyc-preprocess.py
As you can see, the automatically created file name is the same as the file name outside the folder, both _ pycache_. The .pyc extension indicates that the file contains the bytecode of preprocess.py. Cpython represents the type of interpreter. CPython means that the interpreter is implemented in C language. Similarly, JPython is a Python interpreter implemented in Java.
At this point, the study of "how Python works" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.