Python can do so many interesting things, not just artificial intelligence and data analysis, which are hot right now, but crawlers, Web development, and automated operations.

As Python has brought more convenience to our work and life, many people have started to learn Python, paying attention to the development prospects, salary and professionalism of Python.

Therefore, I had a bold idea to write a series of python-related articles in more detail. The first one is to learn the Basics of Python in 20 days, which covers the essential basic knowledge of Python. I hope you can use your spare time to master Python development skills and easily realize your career change.

What is the programming language?

Python code examples:

print("hello world")
Copy the code

This code, which you’ll learn about later in the course, allows the computer to print something like “Hello World” on the screen.

As you can see, this code is made up of English words and punctuation marks. In fact, programming is like writing an essay, except you have to follow some special formatting rules.

But computers process operations based on binary ones and zeros, which is why the world today is called the digital age. This combination of zeros and ones is also called machine language. Machine language is the kind of instruction that a computer can process directly. In other words, computers don’t even know the English words and punctuation marks that we write when we program them.

So how does the code we write actually control the computer?

Just like we have to translate the content into English when we talk to foreigners. If our code is to run, it must be translated, from Python code into machine language. This process is called compilation, and the software used to compile the code is called a compiler.

Programming languages are formal languages used to define computer programs. We write program code through programming language, and then send instructions to the computer through language processing program, so that the computer to complete the corresponding work.

In a nutshell,Programming languages are the languages in which humans and computers communicate.

How does a computer process a program?

According to the principles of von Neumann’s stored programs, the computer works roughly as follows:

The user opens the program, and the program begins to execute; The operating system sends program content and related data into the computer’s memory. The CPU reads instructions from memory based on program contents; The CPU analyzes, processes instructions, and prepares to fetch the next instruction; The next instruction is taken, analyzed and processed, and the process is repeated until all instructions in the program are executed. Finally, the results of the calculation are placed in the memory address specified by the instruction.

Introduction of Python

Python is a programming language invented by Guido von Rossum, a Dutchman.

The history of the Python
  1. Christmas 1989: Guido starts writing a compiler for Python.
  2. February 1991: The first Python interpreter, implemented in C, calls C library functions.
  3. January 1994: Python 1.0 is released.
  4. October 2000: Python 2.0 is released, the entire Python development process becomes more transparent, and the ecosystem slowly begins to form.
  5. December 2008: Python 3.0 is released, introducing many new features of modern programming languages, but not fully compatible with previous Python code.

Note: The version number of most software is generally divided into three sections, such as A.B.C, where A represents the major version number. When the software is completely rewritten or upgraded or there is A backward incompatible change, A will be added. 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.

The advantages of Python

There are many advantages to Python, but here are a few.

  1. Simple and unambiguous, Python is easier to learn than many other languages.
  2. Open source, with a strong community and ecosystem.
  3. It runs on Windows, macOS, Linux and other systems.
The application domain of Python

Python is currently used in Web server application development, cloud infrastructure development, network data acquisition (crawler), data analysis, quantitative trading, machine learning, deep learning, automated testing, automated operations and maintenance, and so on.

Installing Python

To begin your Python programming journey, you must first install the Python environment on your computer. In short, you must install the tools that run Python programs, often called the Python interpreter. We strongly recommend that you install Python 3, which is clearly the better choice for now.

Windows environment

Can be found inPython official websiteFind the download link and download the Python 3 installer.For Windows operating systems, you can download the Executable Installer. Note that if you want to install Python 3 on Windows 7, you will need to install the Service Pack 1 patch, which you can type in the Run TAB on WindowswinverCommand to see if the patch pack is installed on your system. If you don’t have the patch pack, be sure to install it automatically using a tool like “Windows Update” or “CCleaner”, which usually requires you to reboot your Windows system before you start installing Python.Double-click to run the installer you just downloaded to open the Installation wizard for the Python environment. When executing the installation wizard, check the “Add Python 3.x to PATH” option, which will help you Add the Python interpreter to the PATH environment variable, as shown in the following figure. After the installation is complete, you can open the Windows Command Prompt tool and enterpython --versionorpython -VTo check whether the installation was successful, the command line prompt can be entered in runcmdTo open it or find it attached to the Start menu. If you look at the corresponding Python interpreter version number (e.g. Python 3.7.8), your installation is successful, as shown below.

Note: If the installation fails or the above command fails, it is likely that your Windows system is missing some dynamic link library files. If the system displays that the api-ms-win-crt*. DLL file is missing, you can download the Visual C++ Redistributable for Visual Studio 2015 file from the Microsoft official website to rectify the fault. For 64-bit operating systems, you need to download the installation file marked x64. If some dynamic link library files are missing because you updated Windows DirectX when installing the game, you can download a DirectX fix to fix them.

MacOS environment

MacOS comes with Python 2, but Python 3 is what you need to install and use. You can download the macOS Installer from the Download link provided on the Python official website to install Python 3. You do not need to select any box to install Python 3. Click Next. Once installed, you can call the Python 3 interpreter by typing the python3 command in the Terminal tool of macOS, because if you type Python directly, the Python 2 interpreter will be called.

Note: If you have any questions about installing the Python environment, please refer to the video explanation provided on Baidu Cloud Disk.

Follow the Python column in “Environment Installation” for a link to the video.

The use of the PIP

After installing Python, you can see this by looking in the directoryLib is the standard Python library, which contains various library files for development, but these are not enough for future development, we need more third-party extension libraries. Then we need PIP’s help.

PIP is a modern, general-purpose Python package management tool. It provides the functions of searching, downloading, installing, and uninstalling Python packages to facilitate the management of Python resource packages.

The installation

When Python is installed, piPs are automatically downloaded and installed.

configuration

On the Windows command line, typepip -VYou can view the PIP version.If you’re on the command line, runpip -V, the following information is displayed:This may be because it was not checked during the Python installationAdd Python 3.7 to PATHOption to manually configure PIP environment variables.

The manual configuration is as follows:

  • Right clickThis computer–>The environment variable–> Find and double-clickPathIn the popup window, click New –> find the PIP installation directory and add the path.

  • Here’s the newly added pathC:\Users\ Your username \AppData\Local\Programs\Python\Python37\ScriptsIs that once Python is installed,pip.exeThe directory in which the executable resides.

Manage Python packages using PIP

  • pip install The < package name >Installs the specified package
  • pip uninstall The < package name >Deletes the specified package
  • PIP List displays packages that have been installed
  • PIP Freeze displays installed packages in the specified format
  • PIP install -r required. TXT Install the installation packages listed in the required. TXT file

Modify the PIP download source

Run the PIP install command will download from the website specified python package, the default from the https://files.pythonhosted.org/ website. This is a foreign website, when the network is not good, it may fail to download, we can modify the source of PIP current software by command. Format:

PIP install Package name -i Domestic source addressCopy the code

Example: PIP install flask -i https://pypi.mirrors.ustc.edu.cn/simple/ is from science and technology university of China (ustc) on the server to download flask (based on the third party python web framework)

PIP download source list

  • Ali cloud mirrors.aliyun.com/pypi/simple…
  • Pypi.mirrors.ustc.edu.cn/simple/ China university of science and technology
  • Douban (douban) pypi.douban.com/simple/
  • Tsinghua university pypi.tuna.tsinghua.edu.cn/simple/
  • University of science and technology of China pypi.mirrors.ustc.edu.cn/simple/

Introduction to Python summary

At this point, you have a basic understanding of the Python language and know that it can do a lot of things, so it’s worth learning.

To develop with Python, you first need to install The Python environment on your computer. We have introduced the installation method of Python 3 environment on macOS and Windows. We hope that you can successfully install it, so that we can start our subsequent learning. If you encounter any problems with the installation, you can check out the Python column or Q group at 591897914.