Python download installation and basic introduction (Window version)

 

This document is used as a reference for students who have not been exposed to programming, or students who have a certain programming foundation but are not familiar with python. If you are already familiar with the download and installation of python and the basic grammar rules, you can completely ignore this document and directly type the code Come on boy!

1. Download and install

1. Download

We use python3.8.6 version, first enter python's official website (remember not to find unofficial channels to download) Python official website

Then click Downloads to enter the download page 

Generally speaking, this website will automatically jump to the download page of the corresponding system according to whether your operating system is Windows, MacOS or Linux. Here is an example of Windows:

Find the Python3.8.6 version, click download, and enter the download page of python3.8.6:

We pull the page to Files at the bottom:

 

Directly select the simple executable file installation package (executable installer) to install, and choose to download the 64-bit operating system or the 32-bit operating system according to your system bitness.

(Downloading in the domestic network environment may be a bit slow, you can also download "python-3.8.6-amd64.rar" directly from the group file to decompress and install)

 2. Installation

After downloading, just like installing ordinary software, click the exe file to install, and use the default configuration to go to the next step.

After waiting for a while after the installation is successful, in order to change to run python in the command window, we also need to configure python to the system environment variable

3. Configure to system environment variables

If you installed by default, your python will be installed in this directory:

C:\Users\your user name\AppData\Local\Programs\Python\Python38

Right-click Properties on "This PC":

 

Then click System Advanced Settings:

 

Click on Environment Variables:

 Find the system variable Path column:

 

 Double-click this column to pop up the edit environment variable, click New:

 

Enter your python installation path, and then make sure to exit the configuration all the way 

 

 

In this way, your python environment is completely installed and configured, let's test it. Enter cmd in the search bar to open the command window

 

 Open the command window of windows and enter python:

 

Seeing that python3.8.6 is entered proves that the installation is successful!

Ps: If you do not jump to the page for your system correctly, you can also place the mouse on the Download option, each system will be displayed, and then select your system type:

2. Introduction to Python

Python was born to "make programming easier", so it has a minimalist design concept, which is a very good thing for beginners

1. Python program execution mode

There are two ways to execute a python program. Let's first look at a simple execution method supported by all  scripting languages  : 

1.1, interactive mode

After opening cmd, enter python and press Enter to enter the execution environment of python , where we can write and run directly, such as the classic "hello, world":

print is python's printing function, pass in a variable of string type to the function, such as "hello, world", it can be used to print out in the console

Similarly, we can also do the math directly:

 Of course, as we have more and more program codes to write, it is obviously not very convenient in this console window. We generally use the second execution method

1.2. Command mode

We open an editor, and here we recommend using the simple Sublime Text3 software:

First use Ctrl+S (MacOS system is CMD+S) to save the currently edited content to the computer. For example, we put it directly on the desktop and name it test.py:

 Write our program in the test.py source code file:

Remember to press Ctrl+S to save after writing. Then open the CMD command window and enter the directory where the test.py file is located through the cd command

Execute this program with the python command: python test.py

 2. Introduction to the basic syntax of Python

illustrate:

All the details of Python grammar are still very complicated. Here we only briefly introduce some grammar rules commonly used in class. For a more comprehensive and detailed grammar introduction, please refer to the official python3 document:

https://docs.python.org/zh-cn/3.8/

Of course, the domestic "Cainiao Tutorial Network" also provides excellent python3 introductory documents:

Python3 Tutorial | Novice Tutorial

A note: If you already have a programming foundation in other languages ​​but have not written a python program, it is strongly recommended that you skip reading the content at the back of this document and directly choose to browse the above tutorials/documents, where there are more detailed and systematic syntax introduce.

3. Variables and basic data types

Further reading: Python3 Basic Data Types | Novice Tutorial

Python is so simple that there is no need to declare variables at all, and they can be created by directly assigning values ​​​​where they need to be used. Similarly, we don’t need to consider its type when we create it. Although python has types, you don’t have to worry about it. Just go and write.

We use " = " to assign a value to a variable: (in python # is a code comment)

i= 100          # 整型变量  
f= 1000.0       # 浮点型变量  
s= "hello"      # 字符串  
b = True        #布尔变量     
print (i)   # 100
print (f)   # 1000.0
print (s)   # Hello
print (b)   # True

In the above code, we created 4 common types of variables: integer, float, string and boolean, and printed them out.

4. Module

Further reading: Python3 Module | Novice Tutorial

As the saying goes, it is good to enjoy the shade under the big tree, and you can fly on the shoulders of giants. Python has accumulated waves of codes contributed by many developers after so many years of development since its birth. Not surprisingly, the functions we can think of are basically There will be ready-made codes that others have implemented on the Internet, so it is very important to use them directly.

3. About the download and installation of third-party libraries

There are many third-party libraries in Python. Standing on the shoulders of giants has brought us a lot of convenience in programming. For example, in the first lesson, we used the numpy library to do mathematical calculations, but these libraries are not directly installed with python by default. Yes, we need to install it manually.

Of course, as such a cool programming language, python naturally provides a good solution like installing third-party libraries.

There is a Scripts subdirectory under the python installation directory, which provides a tool program called pip:

 This pip is a tool specially used by python to install third-party libraries. First, we also configure this tool in the system environment variable for easy use:

 1. Installation of numpy library

Now we can use pip to install third-party libraries, such as installing numpy libraries, just enter the command:

pip install numpy

Press Enter and wait for everything to be fine. When the word successful appears, we indicate that the library has been installed successfully, which is very convenient.

The numpy library is very important in our machine learning courses. Basically, it needs to be used in any place to do mathematical calculations. It is strongly recommended that you read the official Chinese documentation of numpy directly. You can browse it less carefully to know it. The general function, and then go to the detailed inspection details in the actual programming:

Numpy Chinese documentation:

NumPy User Guide | NumPy

Of course, the download and installation process may be a bit laborious in the domestic network environment. If you are impatient, you can configure a mirror source acceleration for pip. Of course, if you can solve the network problem yourself, you don’t need to configure it.

Tsinghua pip mirror source configuration method: https://mirrors.tuna.tsinghua.edu.cn/help/pypi/

2. Matplotlib library installation

pip install matplotlib

 

 

 

Guess you like

Origin blog.csdn.net/weixin_42019349/article/details/130683971