This is the moment Computer Science stops being theory and becomes something you do. Python is famously beginner-friendly — it reads almost like English. And you don't need to install anything: there's a real Python playground built into this page. Write code, press Run, see it execute. Let's begin.
1Two ways to run Python — and your first program
Python runs your code in two modes:
- Interactive mode (the REPL — Read, Evaluate, Print, Loop): you type one line at a time at a prompt (
>>>) and Python responds immediately. Great for quick experiments. - Script mode: you save many lines in a
.pyfile and run them all together. This is how real programs are written.
The traditional first program prints a message to the screen using the print() function. Try it below — change the text inside the quotes and press Run:
Click Run to execute.
- Interactive mode (REPL) runs one line at a time at the >>> prompt; script mode runs a whole .py file.
- Python is interpreted, so it runs line by line and stops at the first error.
- print() displays output on the screen.
2Tokens: the building blocks of code
Just as a sentence is built from words, a Python statement is built from tokens — the smallest meaningful units. There are a few kinds:
| Token | What it is | Examples |
|---|---|---|
| Keywords | Reserved words with a fixed meaning — you can't use them as names | if, else, for, while, True, None, def |
| Identifiers | Names you give to variables, functions, etc. | age, total_marks, studentName |
| Literals | Fixed values written directly in code | 42, 3.14, "hello", True |
| Operators | Symbols that perform operations | +, -, *, =, == |
Rules for naming identifiers
- May contain letters, digits and underscores (
_) — but cannot start with a digit. - No spaces and no special symbols (like
@,-,%). - Cannot be a keyword (you can't name a variable
for). - Python is case-sensitive:
age,AgeandAGEare three different names.
10, Float 10.5, Complex 3+2j), String ("hi"), Boolean (True/False), and the special literal None (meaning 'no value').- Tokens are the smallest units of code: keywords, identifiers, literals and operators.
- Keywords (if, for, True, None…) are reserved and can't be used as names.
- Identifiers can't start with a digit, can't contain spaces/symbols, can't be keywords; Python is case-sensitive.
- Literal types: numeric (int, float, complex), string, Boolean, and the special None.
3Variables and dynamic typing
A variable is a name that refers to a value. You create one simply by assigning with = — no need to declare its type first:
name = "Asha" age = 16 height = 1.6
This is called dynamic typing: Python figures out the type from the value you assign, and a variable can even be reassigned to a different type later. You can check a value's type with the type() function.
Run the program below, then experiment — change the values, add a new variable, and print it:
# on a line is a comment — Python ignores it. Comments explain your code to humans.Click Run to execute.
- Create a variable just by assigning with = ; no type declaration needed.
- Dynamic typing: Python infers the type from the value, and it can change on reassignment.
- type(x) reports a value's type; a # starts a comment, which Python ignores.
★ Project: an 'About Me' card
In the playground above, write a short program that:
- Stores your name (string), age (integer) and a hobby (string) in three variables.
- Prints a friendly sentence using all three, e.g. using several print() statements.
- Adds a comment explaining what one line does.
- Uses type() to print the type of your age variable — confirm it says int.
Ready for the chapter test?
Answer 5 questions. Score 60% or more to mark this chapter complete.
Start the test →💡 Log in to save your progress and earn the certificate.