"Learning Python with You Hand in Hand" 5-Jupyter Notebook

​Previous article "Learning Python with You Hand in Hand" 4-Hello World! , To introduce the basic content of the print function.

Since the print function is relatively simple and the parameters are not complicated, you only need to directly write the input and output content by hand when you demonstrate the example. But the following content may become more and more complicated, and when it comes to loops and judgments, you need to write multiple sentences. At this time, relying only on direct handwriting input and output may not be very clear.

In addition, we use PyCharm's Console function when performing program input and output. Although it can also achieve our purpose, the interface is not particularly friendly.

So, in this article, I will introduce a new software-Jupyter Notebook, to replace the PyCharm Console function we used in the previous article. In the following articles, I will mainly use Jupyter Notebook to learn Python with everyone, and use similar effects as Jupyter Notebook for program input and display of running results. I hope to bring you a more user-friendly and reading effect.

Jupyter Notebook is a very powerful web application that supports more than 40 programming languages. For readers who have installed Anaconda, Jupyter Notebook is already built-in and can be used directly. For friends who have not installed Anaconda, you may need to find installation and configuration tutorials on the Internet.

The startup of Jupyter Notebook is different from our usual web browsing and application startup. You need to start the "command line" tool in the Windows system, which is called "terminal" in the macOS system.

In Windows system, you can open the command line tool directly in the start menu search cmd function, or you can directly enter the cmd command in the address bar of the explorer to start Jupyter Notebook.

The advantage of the latter method is to enter cmd in the address bar of which folder, and which folder is the path of Jupyter Notebook, which eliminates the need to change the file path with the cd command.

 

In the MacOs system, you can also find the terminal program by searching.

Since MacOS does not have an address bar, you cannot directly enter cmd to determine the file path like Windows. If you need to change the file path in the MacOS system, you can start the terminal, enter two letters cd and a space, and then drag any file in the file path you want to change to the terminal window, then the file path and file The name is displayed after the cd we just entered, delete the file name and press Enter to complete the file path change.

Whether it is Windows or macOS, after determining the file path, directly enter the letters of Jupyter Notebook. After a while, the system will automatically open the browser to start Jupyter Notebook.

 

If it is the first time to use, click "New-Python" in the upper right corner to create a new .ipynb file. If there is already an .ipynb file in the file path, click directly to continue editing and using it.

The user interface of Jupyter Notebook is relatively friendly. It uses an execution-exploration workflow to replace the typical edit-compile-run workflow in other software. Enter the command directly in each box (cell), and then press Shift+Enter to run it, and the result will be displayed directly below each cell.

If there are multiple lines of commands, they can all be written in one cell, or they can be written in different cells and run separately.

Since our coding process will involve a lot of exploration, experimentation, trial and error, and traversal process, using this intuitive editing operation mode can help us complete the programming work faster, and the efficiency and accuracy will be greatly improved. So in the future running examples, I will use Jupyter Notebook to demonstrate to everyone.

The content of the input and output may be taken directly to everyone, or displayed as follows:

In [1]: print('Hello World!')
Out[1]: Hello World!

Among them, after In is the input content, and after Out is the output result. The execution number of Jupyter Notebook is in brackets, you can ignore it.

The input of the entire code block uses the code input function of the WeChat official account editor. Due to some uncertain reasons, part of the code will have some colors, but it does not have any meaning in itself. You can ignore.

In addition, I will also share the sample sentences used in each article on Baidu Netdisk for free download. The format of the download file is Jupyter Notebook's .ipynb file, and you can run it directly in Jupyter Notebook.

But despite this, I still recommend that you can type each sentence letter by letter. Because the input process is also our thinking process, and only after personal input can we better understand the role and function of each sentence, which helps us learn Python more efficiently.

With Jupyter Notebook, you don't need to think that PyCharm is installed for nothing. When you run a complete project in the future, PyCharm is still the best choice, but Jupyter Notebook is more suitable for single statement operation and demonstration.

Starting from the next article, we will start to learn Python strings, welcome everyone to pay attention.

 

 


Thanks for reading this article! If you have any questions, please leave a message and discuss together ^_^

Welcome to scan the QR code below, follow the "Yesu Python" public account, read other articles in the "Learning Python with You Hand in Hand" series, or click the link below to go directly.

"Learning Python with You Hand in Hand" 1-Why learn Python?

"Learning Python with you hand in hand" 2-Python installation

"Learning Python with You Hand in Hand" 3-PyCharm installation and configuration

"Learning Python with You Hand in Hand" 4-Hello World!

For Fans: Follow the "also said Python" public account, reply to "Hand 5", you can download the sample sentences used in this article for free.

Also talk about Python-a learning and sharing area for Python lovers

 

Guess you like

Origin blog.csdn.net/mnpy2019/article/details/98750063