Getting Started with Python
What is Python?
Python is a popular, free, high-level programming language created by Guido van Rossum (released in 1991). Its code looks almost like English, so it is the first language taught in CBSE Classes XI and XII. YouTube, Instagram, NASA and most AI tools use Python.
Same task in C++
#include <iostream>int main() {std::cout << "Hello";return 0; }
Same task in Python
print("Hello")- One line – no main, no semicolons, no brackets
Features of Python
Installing Python and IDLE
- 1Open python.org/downloads and download the latest Python 3 for your computer.
- 2Run the installer. On Windows, tick "Add python.exe to PATH", then click Install Now.
- 3Open IDLE (Integrated Development and Learning Environment) from the Start menu.
- 4You will see the Python shell with the prompt
>>>. Python is ready!
You can also use editors like VS Code, Thonny, PyCharm, or online tools like Google Colab and Jupyter Notebook.
Interactive mode vs script mode
Interactive mode (shell)
- Type a statement after
>>>and press Enter - Result appears immediately
- Great for testing small things
- Code is not saved
Script mode (file)
- Write the full program in a file with .py extension
- IDLE: File → New File, then Run → Run Module (F5)
- Program can be saved, edited and run again
- Used for all real programs
>>> 5 + 3 8 >>> 'Hi' * 3 'HiHiHi' >>> 22 / 7 3.142857142857143
Your first program
In IDLE choose File → New File, type the lines below, save as hello.py and press F5.
print('Hello, Class XI!')
print('My first Python program')
print(25 + 17)print() is a built-in function that shows output on the screen. Text must be inside quotes (single '…' or double "…"); numbers and calculations do not need quotes.
More about print()
print() can show many values separated by commas. Two useful options: sep (what to put between values, default a space) and end (what to put at the end, default a new line).
print('Mango', 'Apple', 'Banana') # sep is a space by default
print('Mango', 'Apple', 'Banana', sep=' | ')
print('Loading', end='...')
print('done')
print() # empty line
print('Rs.', 250 * 3)Comments
A comment is a note for humans; Python ignores it. A single-line comment starts with #. For longer notes you can use a string in triple quotes '''…''' (called a docstring when it describes a function).
# This program finds the area of a circle
radius = 7 # radius in cm
area = 3.14 * radius * radius
print('Area =', area, 'sq cm')Write comments that explain why, not just what. "# 3.14 used as value of pi" helps a reader more than "# multiply".
Keywords
Keywords are reserved words with a special meaning in Python, such as if, for, while, def, True. You cannot use them as variable names.
import keyword
print(len(keyword.kwlist), 'keywords')
print(keyword.kwlist[:10])
print(keyword.iskeyword('for'), keyword.iskeyword('marks'))| All 35 keywords (Python 3.7+) | ||||||
|---|---|---|---|---|---|---|
| False | None | True | and | as | assert | async |
| await | break | class | continue | def | del | elif |
| else | except | finally | for | from | global | if |
| import | in | is | lambda | nonlocal | not | or |
| pass | raise | return | try | while | with | yield |
Identifiers and naming rules
An identifier is the name we give to a variable, function or class. Rules:
- Can contain letters (a–z, A–Z), digits (0–9) and underscore
_. - Must not start with a digit.
- Cannot be a keyword.
- No spaces or special symbols like
@ $ % - !. - Case-sensitive:
Totalandtotalare different.
Valid ✔
markstotal_marks_countstudent2RollNo
Invalid ✘
2nd_name– starts with digittotal marks– has a spacefor– keywordprice$– special symbolmy-name– hyphen means minus
2nd_name = 'Riya'
Use meaningful names: percentage is far better than p when someone else reads your program.
Summary & practice
- Python: easy, free, interpreted, portable, case-sensitive.
- Interactive mode for quick tests; script mode (.py file) for programs.
print()withsepandend; comments start with#.- 35 keywords; identifiers cannot start with a digit or be a keyword.
Which are valid identifiers? Class, class, _9marks, roll-no, none, None. Then write one print statement that outputs 2026-27 using the numbers 2026 and 27 with sep.
Answers: valid: Class, _9marks, none; invalid: class, None (keywords), roll-no (hyphen). print(2026, 27, sep='-')
