Life is short, I use Python, run your first line of Python code with zero foundation

Recently, everyone is learning the scripting language Python. Even those who are not studying computers or working in software are starting to learn it. For example, those who are engaged in finance must learn to use Python for data analysis.

Python is a very easy-to-use and easy-to-learn language. It is very powerful and very simple. Often a few lines of code can complete functions that a bunch of codes in other languages ​​can complete.

Let’s take a look at how people who have never learned programming can play Python.

Main text content:

First find a computer
. What is Anaconda?
Download Anaconda.
Install Anaconda.
Run Jupyter NoteBook
. Change the default directory of Jupyter NoteBook.
Create the first Python file
. Run your first line of Python code.

 

Find a computer first

First of all, you have to find a computer. It is recommended to use a computer with Windows 10 operating system installed. Our courses are mainly taught using Windows 10. Computers with Windows 7 operating system or MacBook computers are also acceptable. They are mainly used in the Python running environment. There will be some differences in installation and operation, but no differences elsewhere.

What is Anaconda

If you want to use Python, you must first install a software - Anaconda

Anaconda is a Python distribution for scientific computing, supports Linux, Mac, and Windows, and contains many popular Python packages for scientific computing and data analysis.

 

Download Anaconda

Because downloading from Anaconda’s foreign official website is relatively slow, we downloaded it from the Tsinghua University software mirror station at the address:

https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/

Drag to the bottom of the web page and find the version "Anaconda3-5.3.1". There are two versions of installation packages for Windows, as shown below:

 Right-click "This PC" on the Windows computer desktop and select Properties:

 View system type:

Choose the corresponding installation package according to your computer situation. My computer is a 64-bit operating system, so what I downloaded here is the 64-bit installation package.

Install Anaconda

After the Anaconda installation package is downloaded, run the installer to start the installation:

 

Click "Next" to continue

Click "I Agree" to agree

 Select the location you want to install here and click "Next" to continue.

 By default, it will not move here. Click "Install" to start the installation.

Wait a few minutes and the installation will be completed

 When the installation is complete, click "Next" to continue.

 

 We don’t need to install VSCode here, click “Skip” to skip

Click "Finish" to complete the installation 

Run Jupyter NoteBook

 Jupyter Notebook is an interactive notebook that supports more than 40 programming languages. It is widely used in the fields of data analysis and financial quantification.
Jupyter Notebook is a very practical python development environment with a friendly interface and simple operation.

We open the "Start Menu", find "Jupyter Notebook" and click to open:

After opening, a command line program will be run first and wait for the program to start.

After the program is started, a web page will automatically open. This will be the development environment for the Jupyter Notebook we will use for Python development in the future.

Note that the black command line program should not be closed during Python development.

 

Change the default directory of Jupyter NoteBook  

As shown in the red box in the picture above, the default working directory of Jupyter NoteBook is the "My Documents" directory of the Windows system. All subsequent code we write will be stored in the working directory. Here we change it to our own directory.

Create a new folder on your computer (for example, my new folder location is: F:\Learn Python in 5 minutes a day):

 Copy this path in the address bar:

 Open the "Start Menu", find "Jupyter Notebook", right-click, find the image below, and click "Open File Location":

 Right-click "Jupyter Notebook" and click "Properties":

 Replace "%USERPROFILE%" with the path we just copied and click "OK":

 

 Close the black command line window, close the Jupyter NoteBook web page, and reopen Jupyter NoteBook.

After reopening Jupyter NoteBook, you can see that the file list is empty. This is because there are no files in the folder we just created.

 Create the first Python file

 Click "New" on the right to create a new Python file:

Click "Untitled" above to rename the newly created file.

Enter a new file name and click "Rename":

 

Returning to the newly created folder, we see that there is already a file of the Jupyter NoteBook we just created with the suffix ".ipynb" in the folder:

Run your first line of Python code

We have completed the software installation above, and now we can finally start programming.

Now we don’t know anything yet, it doesn’t matter, let’s try the simplest one first, let it calculate an arithmetic problem, in the input box we enter:

1+1

 

 Pressing the "Enter" key is to change the line. Holding down "Ctrl" + "Enter" is to execute the command of the line. You can see that it outputs the result to us:

 Delete the command you just entered and enter the following command:

a=1
b=1
a+b

 

 Press and hold "Ctrl" + "Enter" to execute this line of command. You can see that the output result is "3":

Summarize

At this point, we have typed out the first line of Python code and executed the correct results.

Guess you like

Origin blog.csdn.net/chzhe/article/details/127051115