
PYTHON — Creating and Running Code Snippets in Jupyter using Python
The question of whether a computer can think is no more interesting than the question of whether a submarine can swim. — Edsger W. Dijkstra

PYTHON — Intro to Web Scraping with Python
# Creating and Running Code Snippets in Jupyter using Python
Jupyter Notebooks provide an interactive environment to write and execute Python code. In this tutorial, we’ll look at the process of creating and running a code snippet using a for loop inside a Jupyter Notebook. We assume that you have Jupyter Notebooks installed and running on your local machine.
Creating the Code Snippet
- Open Jupyter Notebook and create a new notebook or open an existing one.
- Click on a cell and ensure it’s a code cell (it’s the default type).
- Type the following code into the cell:
for x in range(5): x = x**2 print(x)
Running the Code Snippet
Once the code snippet is written in the code cell, you can run it using one of the following methods:
- Press the Run button in the Jupyter Notebook interface.
- Use the keyboard shortcut Shift + Enter to execute the code.
The output of the code snippet will appear underneath the cell where the code was executed.
Understanding the Output
In Jupyter Notebooks, the structure is different from traditional code editors. It combines the features of a script editor and a Read-Eval-Print Loop (REPL). This means that you get immediate feedback on the code you’re typing, similar to a REPL, but with the advantage of retaining the output of each cell.
One important thing to note is that Jupyter Notebooks do not keep track of the order of execution. This means that variables and their values are retained across cells, and you can access and modify them in subsequent cells. However, it’s important to be mindful of the order in which the cells are executed to avoid confusion.
Conclusion
Jupyter Notebooks provide a dynamic and interactive way of working with code. It’s particularly useful for data exploration and iterative development. In the next video, we will explore how to debug code in Jupyter Notebooks.
By following the steps outlined in this tutorial, you should now be able to create and run code snippets in Jupyter using Python.







