Home  >  Article  >  Backend Development  >  The difference between python language and other languages

The difference between python language and other languages

爱喝马黛茶的安东尼
爱喝马黛茶的安东尼Original
2019-06-24 14:08:195171browse

Python is a weakly typed portable, extensible, and embeddable interpreted programming language with simple and beautiful syntax, extremely powerful functions, a wide range of applications, and powerful and complete third-party libraries. Python has been an object-oriented language from the beginning. It has an important concept that everything is an object.

The difference between python language and other languages

Language features

Concise, elegant, omitting various braces and semicolons, as well as some keywords, types Description etc.

Language type

Interpreted language, when running, interprets and runs line by line. Therefore, debugging code is very convenient and development efficiency is high.

Third-party library

Python is open source, and Python is positioned to allow its development and has many application fields.
Such as Web, operation and maintenance, automated testing, crawlers, data analysis, artificial intelligence, etc. Python has a very complete third-party library.

Related recommendations: "Python Video Tutorial"

Disadvantages

1. The execution speed of Python is not fast enough.

Python is an interpreted language, so its speed is slower than c/c, but it does not affect its use.
Because the current hardware configuration is very high, there is basically no impact, unless some programs with strong real-time performance may be affected. But there is a solution, you can embed c\c code.

2.Python's GIL (Global Interpreter Lock) global interpreter lock.

What is GIL

First of all, make it clear that GIL is not a feature of Python, but a feature of the interpreter. It is a global lock used by Cpython, the Python interpreter, for multi-thread control and scheduling. Ensure that only one thread is running at the same time. Python also has some other interpreters, such as Jpython, which does not have GIL locks. Cpython has now become the implementation standard of python, so we all say that python has GIL restrictions.

GIL problems are generally left over from history. In the past, computer programs ran in a single-core multi-task mode. Therefore, in order to prevent multiple tasks from operating the same resource at the same time and competing for resources, There is a global interpreter lock. However, with the advancement of technology in recent years, multi-cores have appeared. In this case, global locks will limit the parallelism of multi-threads.

Solution

Use multiprocessing (multi-process) instead of Thread (multi-thread)
The emergence of the multiprocessing library makes up for the shortcomings of Python's multi-thread concurrency limit. Each process has its own independent GIL, so there will be no GIL contention between processes.

GIL is just a product of the Cpython interpreter. Of course, it can be replaced by other interpreters. However, because other interpreters do not support C very well, they have not been very popular in many cases.

The Python community is also making some improvements to GIL's support for multi-threading. For example, increase the priority of the thread (high-priority threads can force other threads to release all GI locks).

If you want a program with high parallel computing performance, you can consider writing the core part as a C module, or directly replace it with other languages.

Comparison between Python and Java

Python is simpler than Java. Python is a language where functions are first-class citizens, while Java is a language where classes are first-class citizens. Python is a weakly typed language, while Java is a strongly typed language.

Comparison between Python and C

For use:
Python has a complete class library and is simple to use. Functions implemented with few codes may be very complicated in C. .
For speed:
Compared to C, Python's running speed is definitely very slow. Both Python and CPython interpreters are written in C language.

Compiled and interpreted languages

Interpreted: It is interpreted and executed at the same time.
Compilability: execute after compilation.

The above is the detailed content of The difference between python language and other languages. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn