Hello, readers! In this article, we will introducing Python coding with Jupyter Notebook. So, let us begin with it.
Table of Contents
- 1 1. What is a Jupyter Notebook?
- 2 2. Advantages of Jupyter Notebook
- 3 3. How to Install the Jupyter Notebook?
- 4 4. Jupyter Notebook with Python
- 5 Conclusion
1. What is a Jupyter Notebook?
Let us first understand the concept of the Jupyter Notebook in the tech world. Prior to that, do you guys know what is a notebook in technological terms?
So, a notebook is a development environment that enhances the working of REPL and its experience in coding. REPL is an acronym for read-eval-print-loop. It is a programming environment that performs the following functions–
- The code gets read line by line
- Evaluates, compiles and runs every block of the code independently.
- Prints the error immediately after the block of code.
Jupyter Notebook works upon the above functions and features of REPL or notebook.
To be precise, a Jupyter notebook is an open-source web application that lets us create documents that contain live codes, documental understanding, visualizations, etc.
It executes the code/task per block of the notebook independently and displays the result. By this, different sections of the notebook can be utilized for different purposes such as codes, equations, documentation, graphs, etc.
Having understood about Jupyter notebook, let us now have a look at its plus or merit points.
2. Advantages of Jupyter Notebook
- Code can be written and shared in a live environment i.e. dynamic execution
- Blocks to write documentation of the work
- Dynamic execution of the code blocks at runtime.
- When we open a notebook, it not only displays the code but also the output from the code (if you had previously run the code)
- Data science and machine learning projects can be considered as the biggest application of Jupyter notebooks to handle and maintain large pieces of code.
3. How to Install the Jupyter Notebook?
In order to install, you need to have python environment running on your system.
We would be using Python Manager (PIP) to install the Jupyter notebook on our systems. For the same, make sure you have the latest and upgraded version of pip running using the below command-
python -m pip install --upgrade pip
Further, open the command prompt, and type the below command to install jupyter notebook–
python -m pip install notebook
After the installation, the path of Jupyter notebook gets added to the list of environment variables which in turn helps us run it from the terminal itself.
Last but not the least, let us now open the Jupyter notebook-
To run the notebook, we need to execute the below command in the command prompt,
This opens the UI of notebook on the system’s default browser. To add, the moment you close the terminal, it ends the jupyter notebook session.
4. Jupyter Notebook with Python
In the context of this topic, we will now have a look at the below mentioned features of notebook–
- Creation of folders
- Creation of iPython notebook
- Button icon features to use
- Writing Python code in Jupyter notebook
- Markdown in Jupyter notebook
So, let us begin! 🙂
1. Creation of folders & iPython notebook
On the upper right corner of the notebook, we would find the Files tab. Click on the New button. From the drop-down, select Folder. This would create an untitled notebook in the directory.
I we want to create a new notebook to work on Python, click on the Python 3 from the drop-down under the New button. This would create an Untitled notebook and would appear in a new tab.
Have a look at the below snapshot-
- We can create a new block using + sign.
- Further, we can shuffle the blocks using up arrow & down arrow keys.
- In order to delete a block, the scissor icon can be used.
- The Run button can be used to run the code within a block. Alternatively, Shift + Enter can also be used to run the code.
- The Refresh icon can be used to refresh the notebook. All the variables used within the notebook would be reset.
3. Writing Python code in Jupyter Notebook
We can write and execute python code within blocks as shown below–
The value set to the variables can be used across different blocks and is independent of the scope of the block.
In order to add meaning to the existing codes or equations, we can make use of Markdown in the notebook. You can select Markdown from the drop-down whose default value is Code.
In the markdown, we can add headings to our plain text. For the same, we need to type # and a space to start the heading quote.
Single # is for Heading 1
## for heading 2 and so on..
By this, we have come to the end of this topic. Feel free to comment below, in case you come across any question.
For more such posts related to Python programming, Stay tuned with us.
Till then, Happy Learning!! 🙂
Further read – Jupyter notebook documentation