Skip to content
Python for Data Science
Python Fundamentals 8 min read

Getting Started with Python & Notebooks

Meet Python and the notebook workflow — run your first code, write comments, and use Python as a powerful calculator.

Download notebook Open Google ColabIn Colab: File → Upload notebook → pick the downloaded file.

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):

ShortcutWhat it does
Shift + Enterrun the cell, move to the next one
Ctrl + Enterrun the cell, stay on it
a / binsert a new cell above / below
m / yturn the cell into markdown / code
dddelete 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:

Python — runs in your browser

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:

Python — runs in your browser

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:

OperatorMeaningExample
+addition10 + 3 → 13
-subtraction10 - 3 → 7
*multiplication10 * 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
**exponent10 ** 3 → 1000
Python — runs in your browser

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 — runs in your browser

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:

Python — runs in your browser

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

4 questions · free
  1. Q1.In a notebook, what is the difference between a markdown cell and a code cell?

  2. Q2.What does 17 % 5 evaluate to?

  3. Q3.What is the difference between 7 / 2 and 7 // 2?

  4. 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.