There are different ways to execute Python script. Most common ways:
In this notebook, we explore how to use Jupyter Notebook to run Python code.
For example, the following code output the reuslt of the calculation
1+2
3
In Jupyter notebook, code is spearated into cells
.
example = "This is another cell"
Jupyter notebook shows the result of last line of each cell, if it is not a variable assignment. We call it "Inspection".
Cell is the most special thing in Jupyter notebook.
In normal programming environment, code is executed from top to bottom at once. In Jupyter notebook, code execution is separated, but the state is kept.
example
'This is another cell'
👆🏻 See? We can inspect example
variable that is stored previously.
We can take input by using input()
in Python. It works in Jupyter notebook too. And BE WARE that if you execute the cell twice before entering the input, you will make the kernel dead-loop. If the dead-loop happens, you may choose kernel
> Restart
to escape the dead-loop.
Now here is the code that asks for input.
name = input("What is your name? ")
print(f"Hello {name} :-)")
What is your name? Thomas Hello Thomas :-)
Jupyter notebook comes with some keyboard shortcuts for quicker operation without leaving the hands away from keyboard. In the following, I will show some essential keyboard shortcuts.
Moving selection up and down.
up arrow
or K
.down arrow
or J
.ENTER
to edit the current selected cell.
The cell selection shows blue border by default. It turns into green border when toggled into editing mode.
Here are some keyboard shortcuts.
CTRL+ENTER
to execute the current cell.
SHIFT+ENTER
to execute the current cell and move to next cell
There are mainly two types of cells: Code and Markdown.
Code is for Python execution and Markdown is for copy writings.
M
.Y
.Inserting cells below or above the current selection.
A
to insert a cell above the current cell.B
to insert a cell below the current cell.In this notebook, we learned to operate Jupyter notebook and some keyboard shortcuts to master it. In next notebook, we will learn the Python variables.