📘 CodingMarble Learn

Getting Started with Python

Python is a high-level, free and open-source, interpreted, portable, case-sensitive language that is easy to read. You can run it in interactive mode (type after the >>> prompt and see the result at once) or script mode (save code in a .py file and run it). Python's character set includes letters, digits, special symbols, whitespace and all Unicode characters. The smallest units of a program are tokens: keywords, identifiers, literals, operators and punctuators. A variable is a name that refers to a value; in an assignment the right side (r-value) is evaluated first and stored in the left side (l-value). Comments start with # and are ignored by Python.

🎬 Step-by-step story

  1. Python is easy to read, free, and runs on any computer. It runs your code line by line.
  2. In interactive mode you type after >>> and see the answer at once. In script mode you save a file and run it all.
  3. Python breaks each line into tokens: names, values, operators and symbols. A comment after # is skipped.
  4. A variable is a name tag on a value. When you give it a new value, the tag moves to the new value.
  5. In x = y + 5, the right side is worked out first. Then the answer is stored in the name on the left.
  6. Your turn: type a value and see the name tag and its type.

Tip: drag the 3D scene to turn it. Use two fingers to zoom.

🤔 Common doubts, cleared

Why does Python run line by line?

Python uses an interpreter, so each line is translated and run in turn. That is why an error stops the program at that line.

When should I use interactive mode?

For quick tests like 7 * 8 or checking a function. Use script mode for real programs you want to save.

Is a comment a token?

Python skips comments while reading, so they do nothing to the program. Watch the # bill block stay see-through.

Does b change if I change a after b = a?

No. b = a puts a second tag on the same value. Moving tag a later leaves tag b where it was.

Why is 5 = x wrong?

The left side must be a name that can hold a value. 5 is a fixed literal; it cannot be given a new value.

Features of Python

Your first program: Hello World

print("Hello World")

print() is a built-in function that shows its value on the screen. Text is written inside quotes. Python has no semicolons at line ends and uses indentation to group lines.

Interactive mode and script mode

Interactive mode: type one statement after the >>> prompt and press Enter; the result appears immediately. Good for testing small things, but the code is not saved.

Script mode: write many lines in a file with the .py extension, save it, and run it (in IDLE: Run → Run Module or F5). The program can be saved, edited and run again.

Python character set

The characters Python accepts: letters A–Z, a–z; digits 0–9; special symbols like + − * / ( ) [ ] { } = , : ' " # @; whitespace (space, tab, newline); and other Unicode characters.

Tokens

A token is the smallest meaningful unit of a program.

Variables

A variable is a name that refers to a value stored in memory. It is created when you first assign to it: age = 15. Python does not need you to declare the type; it takes the type from the value. Giving a new value makes the name refer to the new object: age = 16.

Multiple assignment: a = b = 0 and x, y = 2, 5. Every object has an identity (id()), a type (type()) and a value.

l-value and r-value

In x = y + 5:

5 = x and a + b = c are errors because the left side is not a name.

Comments

A comment is a note for humans that Python ignores. A single-line comment starts with #: # find the total. For a multi-line note, programmers often use a triple-quoted string '''…''' (a docstring when placed at the start of a function or file). Comments explain why the code does something and make it easier to read and debug.

Key formulas and definitions

Worked examples

1. Which of these identifiers are valid? total_marks, 2ndPlace, _count, my-name, while, Name1

Valid: total_marks, _count, Name1. Invalid: 2ndPlace (starts with a digit), my-name (hyphen), while (keyword).

2. Count the tokens in: area = 3.14 * r * r

Tokens: area, =, 3.14, *, r, *, r → 7 tokens (identifiers: area, r, r; operators: =, *, *; literal: 3.14).

3. What is printed? a = 5; b = a; a = 7; print(b)

5. b was tagged to the value 5; moving the tag a to 7 does not move b.

4. Find the error: 10 = marks

The left side must be a variable (l-value). Correct: marks = 10.

5. What does x, y = y, x do if x = 2, y = 9?

The right side (9, 2) is made first, then assigned: x = 9, y = 2. The values are swapped.

6. What will Python show? print('Sum', 4 + 5) # adding

Sum 9. The comment after # is ignored.

Common mistakes

Practice quiz

1. Which is a keyword in Python?
2. The prompt >>> is seen in:
3. Which identifier is invalid?
4. A comment in Python starts with:
5. In a = b + 1, the l-value is:

Practice: answer these yourself

Type or choose your answer, then press Check. Use a hint if you are stuck; the full solution appears after you answer.

Frequently asked questions

What are tokens in Python?

The smallest units of a program: keywords, identifiers, literals, operators and punctuators.

What is the difference between interactive and script mode?

Interactive mode runs one statement at a time at the >>> prompt and does not save code; script mode runs a saved .py file.

What are l-value and r-value?

In an assignment, the r-value is the expression on the right that is evaluated; the l-value is the variable on the left that receives it.

Where this is taught

CBSE (India)Class 11Python Programming
CBSE (India)Class 11Computational Thinking and Programming - 1
CBSE (India)Class 11Introduction to Python
FranceSecondeAlgorithms and logic
FranceSecondeProgramming basics
FrancePremièreAlgorithms and logic
FrancePremièreLanguages and programming
FrancePremièreMathematics (2026 programme)
FranceTerminaleContent
FranceTerminaleMathematics (2019 programme)

Learn first

Learn next

Related lessons

All Computer Science lessons