VM-LEARNING /class.xi ·track.cs ·ch-2-2 session: 2026_27
$cd ..

~/Getting Started with Python

root@vm-learning ~ $ open ch-2-2
UNIT 2 ▪ CHAPTER 2
08
Getting Started with Python
Python basics · Execution modes · Tokens · Variables · Comments
Python is a high-level, general-purpose, interpreted programming language created by Guido van Rossum and first released in 1991. It is famous for its clean, readable syntax — so much so that its design motto is "There should be one — and preferably only one — obvious way to do it." Today Python powers Google Search, YouTube, Instagram, machine-learning research, scientific data analysis, Raspberry Pi projects, and the CBSE Class XI & XII programming course. This chapter takes you from "What is Python?" to writing your first real program.
Why Python is the chosen teaching language:
  • It reads like English — students can focus on problem solving rather than wrestling with syntax.
  • It is free and open-source — runs on Windows, macOS, Linux and Raspberry Pi without any licence cost.
  • It has a huge standard library and thousands of third-party modules (NumPy, Pandas, Matplotlib, scikit-learn, Flask, Django, Pygame…).
  • A beginner can write useful code in a single afternoon; a professional can build production systems in it.
Learning Outcome 1: Describe what Python is and list its main features.

8.1 Introduction to Python

Python was born at Centrum Wiskunde & Informatica (CWI) in the Netherlands in December 1989, when Guido van Rossum was looking for a "hobby project" over the Christmas break. The language was named after the British comedy group Monty Python's Flying Circusnot the snake (although the snake logo is now the official mascot).

MilestoneYearHighlights
Python 1.01994First public release — functions, modules, exceptions.
Python 2.02000List comprehensions, garbage collection.
Python 3.02008Big overhaul; broke backward compatibility. print() becomes a function.
Python 3.122023Better error messages, faster interpreter.
Current (2026)3.13+Now the dominant version worldwide; Python 2 is officially retired.
Always install Python 3 from python.org. Any Python-2 tutorials you find online are out-of-date and will not work unchanged in Python 3 — notably print x (Python 2) is now print(x).

8.2 Features of Python

Python stays popular because it checks almost every box a modern language should. The nine features below are the ones CBSE examines most often.

FeatureMeaning
Easy to learn & readableSyntax is close to plain English; indentation replaces {/} blocks, so code is visually clean.
Free & open-sourceAnyone can download, use, modify and redistribute Python at no cost.
Platform-independentThe same .py file runs on Windows, macOS and Linux without changes.
InterpretedNo separate compile step. The interpreter reads the source line by line and executes it immediately.
Dynamically typedYou do not declare a variable's type — Python figures it out from the value you assign.
Rich standard library"Batteries included" — comes with modules for maths, random numbers, files, dates, web, regex and much more.
Object-orientedSupports classes, inheritance and objects — while allowing a simple "script style" for small programs.
Extensible & embeddableCan call C / C++ code for speed, and can itself be embedded into larger applications.
GUI & web readyTkinter ships with Python for GUIs; Django and Flask power major websites.

8.3 Your First Program — "Hello, World!"

A long tradition: every programming lesson begins with a program that prints a greeting. In Python it is just one line.

print("Hello, World!")

Save the file as hello.py, open a terminal in that folder, and run:

python hello.py

Expected output:

Hello, World!
Anatomy of the line:
  • print — a built-in function that writes to the screen.
  • () — parentheses send arguments to the function.
  • "Hello, World!" — a string literal, the text to be printed.
No semicolons, no main(), no compilation — you are writing Python.
Learning Outcome 2: Execute Python code in interactive mode and in script mode.

8.4 Execution Modes — Interactive vs. Script

Python can be used in two complementary ways.

Interactive mode vs. Script mode: Interactive Mode (REPL) Read – Evaluate – Print – Loop Python 3.13 on win32 Type "help" for more information. >>> 2 + 3 5 >>> print("Hi") Hi Best for quick tests, experiments, calculator-style use. Code is not saved after the shell closes. Script Mode Type the code in a .py file, then run it # hello.py name = "Aarav" print("Hi,", name) Then at the terminal: python hello.py Output: Hi, Aarav Best for real programs; code is saved and reusable.

8.4.1 Comparison

CriterionInteractive ModeScript Mode
How you enter codeOne line at a time at the >>> promptWrite the whole program in a .py file
Output shownAfter every statementOnly what print() produces
Code saved?No — lost when you close the shellYes — the .py file persists
Good forQuick tests, exploring, calculator useReal programs, assignments, projects
How to startType python (or open IDLE) in a terminalCreate file.py, run python file.py
Popular editors / IDEs for script-mode work: IDLE (ships with Python), VS Code (free, recommended), PyCharm, Jupyter Notebook (great for data work), Thonny (beginner-friendly).
Learning Outcome 3: Identify the Python character set and classify Python tokens.

8.5 Python Character Set

The character set of a language is the collection of symbols it understands. Python uses the full Unicode character set, but the characters you will actually type in your code fall into four groups:

CategoryCharacters
LettersA – Z, a – z (and any Unicode letter — Python 3 accepts names like गिनती or número)
Digits0 – 9
Special symbols+   −   *   /   %   =   <   >   (   )   [   ]   {   }   ,   .   :   ;   #   '   " and so on
WhitespaceSpace, tab, newline — significant in Python because indentation defines blocks.

8.6 Python Tokens

When Python reads your source code, the very first job of the interpreter is to chop the text into small meaningful pieces called tokens. A token is the smallest unit of a program that has meaning to the compiler. Python has five kinds of tokens:

The five Python tokens: Python Tokens smallest meaningful units Keywords reserved words if · else · for while · def class · return Identifiers names we create name · age total_marks print · Student Literals raw values 42 · 3.14 "hello" True · None Operators do something + − * / % == != < > and · or · not Punctuators structure the code ( ) [ ] { } , : ; . " ' #

8.6.1 Keywords

Keywords are reserved words that have a fixed meaning in Python. You cannot use them as the name of a variable, function or class. Python 3.13 has 35 keywords; you do not need to memorise all of them, but you will meet every one during Class XI & XII.

35 Python Keywords (alphabetical)
FalseNoneTrueandas
assertasyncawaitbreakclass
continuedefdelelifelse
exceptfinallyforfromglobal
ifimportinislambda
nonlocalnotorpassraise
returntrywhilewithyield
You can see the up-to-date list at the Python prompt:
import keyword
print(keyword.kwlist)

8.6.2 Identifiers

An identifier is a name that you give to something in your program — a variable, a function, a class, a module. Identifiers follow strict rules:

Rules for a valid Python identifier:
  • Must start with a letter (A – Z or a – z) or an underscore _. Cannot start with a digit.
  • The remaining characters may be letters, digits (0 – 9) or underscores.
  • Identifiers are case-sensitiveName, name and NAME are three different names.
  • A keyword from the table above cannot be used as an identifier.
  • There is no fixed length limit.
  • Special characters such as @ # $ % are not allowed inside a name.
ExampleValid?Why
nameStarts with a letter.
student_ageLetters + underscore.
_totalStarts with underscore.
Marks2024Digits allowed after a letter.
2marksStarts with a digit.
student-ageContains a hyphen (looks like subtraction to Python).
forIs a keyword.
first nameContains a space.
total@marksContains a special symbol.

8.6.3 Literals

A literal is a fixed value written directly in the source code. Python supports five groups:

TypeExamples
Integer literal0, 100, −37, 1_000_000 (underscores allowed for grouping)
Floating-point literal3.14, −0.5, 6.022e23 (e for ×10ⁿ)
String literal"hello", 'world', """triple-quoted spans many lines"""
Boolean literalTrue, False (note the capital T and F)
None literalNone — represents "no value / nothing"

8.6.4 Operators

An operator is a symbol that tells Python to perform some action on one or two values (called operands). The full treatment of operators comes in Chapter 10; here is a preview:

8.6.5 Punctuators

Punctuators are symbols used to structure a program. They do not act on data directly; they tell Python where things start and end.

SymbolUsed for
( )Function call / grouping in expressions
[ ]Lists, indexing, slicing
{ }Dictionaries and sets
,Separating items in a list, arguments, etc.
:Marks the start of an indented block (if, while, def …)
.Access attribute or method — math.pi, name.upper()
' "String delimiters
#Begins a single-line comment
;Optional — separates multiple statements on one line
Learning Outcome 4: Create variables, understand l-value and r-value, and write comments.

8.7 Variables

A variable is a named reference to a value stored in the computer's memory. In Python you do not declare a variable's type — you just assign a value using the = operator, and Python figures out the type automatically.
name = "Ananya"      # string
age  = 16            # integer
pi   = 3.14159       # float
can_vote = False    # boolean

print(name, age, pi, can_vote)

Output: Ananya 16 3.14159 False

Dynamic typing. The same variable can hold values of different types at different moments — Python simply updates its binding.
x = 10           # x is an int
x = "hello"      # now x is a string — perfectly legal

8.7.1 How an assignment works — the Box Model

When you write age = 16, Python does three things:

  1. Creates an integer object 16 in memory.
  2. Creates a name age.
  3. Makes age refer to the object.
Variable binding — the name points to a value: age (name) name (name) 16 int object · stored at 0x104a2f0 "Ananya" str object · stored at 0x104a4b8 Names (left) Objects in memory (right)

8.8 L-Value and R-Value

Every assignment statement in Python (or any C-family language) has two sides separated by =:

L-value  =  R-value
marks = 85
# L-value: marks  (a variable — can hold a value)
# R-value: 85     (the value being stored)

area = length * breadth
# L-value: area
# R-value: length * breadth  (an expression, evaluated first)
Why the distinction matters. An R-value can appear anywhere, but an L-value must be something that addresses memory. These are not valid:
10 = marks          # ❌ 10 is not a location
marks + 5 = 100      # ❌ an expression cannot be an L-value
You will see this idea again in C++ and in pointer-based languages.

8.9 Comments

A comment is text inside the source file that Python ignores. Comments exist for human readers — to explain why a piece of code exists, a non-obvious shortcut, or a reminder to fix something later.

8.9.1 Single-line comments (#)

Anything from # to the end of the line is a comment.

# Compute the GST-included price
price = base * 1.18      # 18% GST

8.9.2 Multi-line "comments" (triple-quoted strings)

Python has no formal multi-line comment syntax. The common trick is to use a triple-quoted string, which Python will evaluate and immediately discard if it isn't assigned to anything.

"""
This function computes the area of
a rectangle given its length and breadth.
Returns a float rounded to 2 decimal places.
"""
def area(length, breadth):
    return round(length * breadth, 2)
When a triple-quoted string is the first thing inside a function, class or module, Python stores it as the object's docstring — which can be read later via help(). That is why the convention above is so useful.

8.9.3 Why write comments?

Good comment, bad comment:
# ❌ WHAT — useless, the code already says this
i = i + 1              # add 1 to i

# ✓ WHY — valuable, captures the intent
i = i + 1              # skip duplicate row — see issue #42
Aim for the second style.

📌 Quick Revision — Chapter 8 at a Glance

  • Python — created by Guido van Rossum (1991); named after Monty Python's Flying Circus. High-level, interpreted, dynamically typed.
  • Key features: easy / readable · free & open-source · platform-independent · interpreted · dynamically typed · huge standard library · object-oriented · extensible · GUI & web ready.
  • Hello World: print("Hello, World!"). Run with python hello.py.
  • Execution modes:
    • Interactive — REPL at >>> prompt; quick tests, output after every line, code not saved.
    • Script — code in a .py file; real programs; saved & reusable.
  • Character set: letters, digits, special symbols, whitespace (significant in Python).
  • Five tokens: Keywords · Identifiers · Literals · Operators · Punctuators.
  • Keywords — 35 reserved words (if, else, for, while, def, class, True, False, None, …). Cannot be used as names.
  • Identifier rules: start with letter/_, then letters/digits/_; case-sensitive; no keywords; no spaces or special symbols.
  • Literals: Integer, Float, String, Boolean (True/False), None.
  • Variables: bound with =; type inferred automatically; same name can be rebound to any type.
  • L-value / R-value: L-value is the location (a name); R-value is the value (literal or expression). L = R.
  • Comments: # for single-line; triple-quoted strings for multi-line / docstrings. Write why, not what.
🧠Practice Quiz — test yourself on this chapter