Jupyter notebooks let you combine executable code, results, and explanatory text in separate cells. Modern unified PyCharm includes core notebook support.
Understanding the Concept
Create or open a .ipynb file and select an available Python kernel. Run one code cell at a time and inspect the output beneath it. Markdown cells hold notes, headings, and explanations. Unlike a typical .py script, notebook cells can be run out of order, so old variables may remain in memory. Restarting the kernel and running all cells from the top helps verify the document is reproducible.
When and Why You Would Use This
A notebook is useful for experiments and data exploration, but ordinary .py files remain the main format used in this beginner course. Prefer scripts when you want an unambiguous execution order and simple project files.
Practical Example
sales_amounts = [20, 35, 15]
sales_total = sum(sales_amounts)
sales_total
Understanding the Example
In a notebook cell, the last expression often displays its value automatically: 70. In an ordinary .py script, add print(sales_total) to see console output. The example is small so you can compare the two execution models.
Try It Yourself
Create one notebook with a Markdown heading and the sample calculation. Restart the kernel and run it from the top.
Common Beginner Mistakes
- Running cells out of order and relying on variables created only in an earlier notebook session.
- Expecting a bare expression in a .py script to print a result automatically.
- Selecting a kernel that uses a different Python version than the project interpreter.
Key Takeaways
- Notebooks mix code, output, and explanatory text.
- Run all cells from a clean kernel to confirm reproducibility.
- Use scripts for straightforward programs and notebooks for interactive exploration.