Getting Started with Python & Notebooks
Meet Python and the notebook workflow — run your first code, write comments, and use Python as a powerful calculator.
Every data scientist's toolbox starts in the same place: Python and a notebook. In this lesson you'll learn why Python became the language of data science, how notebooks organize your work into runnable cells, and how to write your very first lines of code — printing messages, doing arithmetic, and storing results in variables.
You can run every code block right here in the browser, or download this lesson as a Jupyter notebook and open it in Google Colab. Either way, the code is identical.
Why Python?
Python is a general-purpose programming language, but it has utterly dominated data science for a decade. A few reasons why:
- Readable syntax — Python code often looks like plain English, so you spend your energy on the problem, not the language.
- The ecosystem — pandas for tables, NumPy for math, matplotlib for charts, scikit-learn for machine learning, PyTorch for deep learning. Almost every data tool speaks Python first.
- Interactive by design — you can type one line, run it, see the result, and adjust. That tight feedback loop is exactly how data exploration works.
You don't need to be a software engineer to use Python well. This module teaches just the core you'll use every day as a data practitioner.
Notebooks: code in cells
A notebook (Jupyter locally, or Google Colab in the cloud) is a document made of cells. There are two kinds:
- Markdown cells hold formatted text — headings, bullet points, notes to
yourself. A
#makes a big heading,##a smaller one. - Code cells hold Python. You run a cell and its output appears directly below it.
This mix of prose and runnable code is why notebooks rule data science: your analysis and its explanation live in one document.
A few keyboard shortcuts worth memorizing (press Esc first, then the key):
| Shortcut | What it does |
|---|---|
Shift + Enter | run the cell, move to the next one |
Ctrl + Enter | run the cell, stay on it |
a / b | insert a new cell above / below |
m / y | turn the cell into markdown / code |
dd | delete the cell |
Execution order matters
Cells run in the order YOU run them, not the order they appear on the page. If a cell uses a variable defined in another cell, that other cell must have been run first. When a notebook gets confusing, use "Restart & Run All" to re-run everything top to bottom.
Your first code: print()
The print() function displays whatever you put between the parentheses.
Text (a string) goes in quotes. Try running this — then edit the message
and run it again:
Notice each print() produces one line of output. In a notebook, the last
expression in a cell is also displayed automatically, but print() works
everywhere and shows exactly what you ask for — we'll use it constantly.
Comments: notes the computer ignores
Anything after a # on a line is a comment. Python skips it entirely;
it exists purely for humans reading the code. Good comments explain why,
not just what:
Commenting out a line (adding # in front) is also a handy way to
temporarily disable code while debugging.
Python as a calculator
Before variables, functions, or data frames, Python is a very good calculator. The arithmetic operators:
| Operator | Meaning | Example |
|---|---|---|
+ | addition | 10 + 3 → 13 |
- | subtraction | 10 - 3 → 7 |
* | multiplication | 10 * 3 → 30 |
/ | division (always gives a decimal) | 10 / 3 → 3.333… |
// | floor division (drops the remainder) | 10 // 3 → 3 |
% | modulo (the remainder itself) | 10 % 3 → 1 |
** | exponent | 10 ** 3 → 1000 |
Two of these deserve a closer look because they show up constantly in data
work. The modulo operator % tells you the remainder after division —
which makes it the classic even/odd test. And ** with a fractional power
gives you roots:
Python also respects the usual math precedence: ** before * and /,
which come before + and -. Use parentheses whenever there's any doubt —
(2 + 3) * 4 is clearer than trusting the reader to remember the rules.
Your first variables
Retyping numbers gets old fast. A variable is a name that stores a value
so you can reuse it. You create one with =, the assignment operator:
Read = as "gets", not "equals": total = price * quantity means "compute
the right side, then store it under the name total". If you assign to the
same name again, the old value is simply replaced — variables always hold
their most recent assignment.
Run it here or in Colab
Every lesson in this course has a "Download notebook" option. The generated .ipynb opens directly in Jupyter or Google Colab, so you can practice with real notebook shortcuts. For quick experiments, the in-browser runners on this page are all you need.
Check your understanding
Q1.In a notebook, what is the difference between a markdown cell and a code cell?
Q2.What does 17 % 5 evaluate to?
Q3.What is the difference between 7 / 2 and 7 // 2?
Q4.After running x = 10 and then x = 25, what does print(x) show?
Exercise: A tip calculator in three variables
A dinner bill is 480000 rupiah, you want to leave a 10% tip, and 3 people are
splitting the total evenly. Using variables (no hard-coded intermediate
numbers), compute and print: the tip amount, the grand total, and each
person's share. Bonus: use // and % to figure out how many full
groups of 8 fit into 100, and what's left over.
Next up: variables get much more interesting once you know Python's data types — numbers, text, lists, and dictionaries.