Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”.

Hello everyone, I am a bowl week, a front end that does not want to be drunk (inrolled). If I am lucky enough to write an article that you like, I am very lucky

Introduction of Python

The history of the Python

  1. Christmas 1989: Guido von Rossum starts writing a compiler for Python.
  2. February 1991: The first Python compiler (and interpreter), implemented in C (later), can call C library functions. In its earliest versions, Python already provided support for building blocks such as classes, functions, and exception handling, as well as for core data types such as lists and dictionaries, and for building applications on a modular basis.
  3. January 1994: Python 1.0 is released.
  4. October 16, 2000: Python 2.0 is released, adding full garbage collection and providing Unicode support. At the same time, the Python development process became more transparent, the community’s influence on the development schedule expanded, and the ecosystem began to form.
  5. December 3, 2008: Python 3.0 is released. It is not fully compatible with previous Python code, but many of the new features of Python 3.x have since been ported to Python 2.6/2.7, since many companies still use Python 2.x for projects and operations.

The current version of Python we use, 3.7.x, was released in 2018. The Python version number is in three segments, shaped like A.B.C. Where, A represents the large version number. Generally, A is added when the whole version is overwritten or backward incompatible changes occur. B represents function update, and B is added when a new function appears. C represents minor changes (e.g., fixing a Bug), and C is added whenever there are changes. If you are interested in the history of Python, you can read a web article called a Brief History of Python.

Pros and cons of Python

Python has many advantages, which can be summarized briefly in the following points.

  1. Simple and straightforward, with a low learning curve, it’s easier to learn than many programming languages.
  2. Open source, with a strong community and ecosystem, especially in data analytics and machine learning.
  3. Interpreted languages are inherently platform portable, and code can work on different operating systems.
  4. Support is provided for both the dominant programming paradigms, object-oriented and functional.
  5. Code specification degree of high readability, suitable for code cleanliness and obsessive-compulsive crowd.

Python’s shortcomings focus on the following points.

  1. The parts that require high execution efficiency can be written in other languages (such as C and C++).
  2. The code cannot be encrypted, but now that many companies sell services rather than software, this problem is mitigated.
  3. There are so many frameworks to choose from at development time (Web frameworks, for example, have more than 100) that where there are choices, there are mistakes.

The application domain of Python

Python is widely used in Web application backend development, cloud infrastructure construction, DevOps, Web data acquisition (crawler), automated testing, data analysis, machine learning and other fields.

Install the Python interpreter

Installing the Python interpreter is relatively simple and will not be demonstrated here

Run a Python program

Check whether Python is installed

On the Windows command line, type the following command:

Python --version # python 3.10.0Copy the code

You can also enter Python or Python3 to enter the interactive environment, and then check the Python version by executing the following code.

Python # Python 3.10.0 (tags/ V3.10.0: B494F59, Oct 4 2021, 19:00:18) [MSC V. 1929 64-bit (AMD64)] on win32 # Type "help", "copyright", # >>> Import sys # >>> print(sys.version) # 3.10.0 (tags/ V3.10.0: B494F59, Oct 4 2021, 19:00:18) [MSC v.1929 64 bit (AMD64)] # >>> exit()Copy the code

Writing Python source code

You can write Python source Code with a text editing tool (advanced text editing tools such as Sublime, Visual Studio Code are recommended) and save the file with py as the suffix. The Code looks like this:

print('hello, world! ')Copy the code

To run the program

Switch to the source directory and execute the following command to see if “Hello, world!” is printed on the screen. .

python hello.py
Copy the code

or

python3 hello.py
Copy the code

annotation

Comments are an important part of programming language. They are used to explain the functions of the code in the source code to improve the readability and maintainability of the program. Of course, they can also be used to remove the code segments in the source code that do not need to be run. Comments are removed when the source code is entered into the preprocessor or compiled. They are not retained in the object code and do not affect the execution of the program.

  1. One-line comment: to#And the beginning of the space
  2. Multi-line comments: three quotes at the beginning and three quotes at the end
# print hello world print('Hello world ')Copy the code