Python is a popular, easy-to-learn, high-level programming language. Created by Guido van Rossum and first released in 1991. The name was inspired by the British comedy Monty Python's Flying Circus, not the snake.
print("Hello") simply prints "Hello". This is why it is the first language taught in most schools and colleges today.Web back-ends (Django, Flask), data science & machine learning, scientific computing, automation scripts, game scripting, network tools, and most beginner courses around the world.
The classic first program in any language is the Hello World program. In Python it is just one line:
print("Hello, World!")
Output: Hello, World!
| Mode | How it works |
|---|---|
| Interactive (REPL) | Open the Python shell, type one statement, press Enter, see result instantly. Good for trying things and quick maths. Cannot be saved. |
| Script | Write the full program in a .py file using an editor (IDLE, VS Code) and run with python file.py. Good for big reusable programs. |
>>> 2 + 3 5 >>> print("hi") hi >>> "py" * 3 'pypypy'
>>> is the prompt — you don't type it.greet.py):
name = "Vivek" print("Hello", name) print("Welcome to Class XI")Run it:
python greet.py. Both prints execute in order.2 + 3) shows the result. In script mode, you must use print() to see anything — the shell does not auto-display.The character set is the collection of symbols Python understands when you write code:
+ - * / % = < > ( ) [ ] { } : ; , . " ' # \ _ & | ! ? @A token is the smallest meaningful piece of Python code — a "word" of the language. Python splits your code into tokens before running it.
| Type | Examples |
|---|---|
| Keywords | if, else, for, while, def, return, True, False, None, in, and, or, not, import |
| Identifiers | marks, total_score, _x1, RollNo — names you give |
| Literals | 10, 3.14, "hi", True, None — fixed values written as-is |
| Operators | + - * / // % ** == != > < and or not = |
| Punctuators | ( ) [ ] { } , : ; . — help group code |
x = 5 + 3:
x → identifier= → operator (assignment)5, 3 → literals (numbers)+ → operatorif x > 0:
— if is a keyword, x is an identifier, > is an operator, 0 is a literal, : is a punctuator. Five tokens here too.Words that already have a fixed meaning in Python — you cannot reuse them as variable names. Python 3 has about 35 keywords:
if, else, elif, for, while, break, continue, def, return, class, import, from, as, in, is, and, or, not, True, False, None, pass, lambda, with, try, except, finally, raise, global, nonlocal, yield, del, assert
True, False, None begin with a capital letter. Writing true or FALSE is wrong — gives NameError.An identifier is the name you give to a variable, function, class or module.
Rules:
_.@ # $ %, hyphen).Marks and marks are two different names.name, total_marks, _count, mark1, RollNo, x_2y.1name (digit start), total marks (space), class (keyword), my-var (hyphen), price$ (dollar).A literal is a value written directly in the program. Six common types:
| Type | Examples |
|---|---|
| Integer | 10, -3, 0, 1000000 |
| Float | 3.14, -0.5, 2.0, 1.5e3 |
| Complex | 2 + 3j, -4j |
| String | "hello", 'Python', "123" |
| Boolean | True, False |
| Special | None (means "no value") |
"It's fine". Use triple quotes """ """ for multi-line strings.| Group | Symbols |
|---|---|
| Arithmetic | + - * / // % ** |
| Relational | == != > < >= <= |
| Logical | and or not |
| Assignment | = += -= *= /= //= %= **= |
| Identity | is is not |
| Membership | in not in |
| Bitwise | & | ^ ~ << >> |
/, //, % and **:
print(7 / 2) # 3.5 (true division, float) print(7 // 2) # 3 (floor division, int) print(7 % 2) # 1 (remainder) print(2 ** 5) # 32 (2 to the power 5)
x = 10 x += 5 # same as x = x + 5 -> 15 x *= 2 # same as x = x * 2 -> 30 x //= 4 # same as x = x // 4 -> 7
print("py" in "python") # True print(5 not in [1, 2, 3]) # True a = [1, 2] b = a print(a is b) # True (same object)
Symbols that group or separate parts of code: ( ) for function calls, [ ] for lists/indexing, { } for dicts, , separates items, : after if/for/while/def, . for attribute access, ; rarely — to put two statements on one line.
= (assignment) with == (equality test). x = 5 stores 5; x == 5 asks "is x equal to 5?".A variable is a name that refers to a value. The statement x = 5 reads as "name x points to value 5".
x = 5 creates a box x and puts 5 inside. Doing x = 8 later replaces 5 with 8 — the label stays the same.Python is dynamically typed — the same variable can hold different types over time:
x = 10 # int x = "hello" # now a string x = 3.14 # now a float x = [1, 2, 3] # now a list
In an assignment L = R:
=. Must be a name where a value can be stored.marks = 47 → L-value: marks · R-value: 47.5 = marks → error: 5 cannot be an L-value (you can't store anything inside a literal).a = b = c = 0 # all three become 0 x, y = 5, 8 # x = 5, y = 8 x, y = y, x # swap, no temp needed
Comments are notes for humans — Python ignores them.
| Style | How to write |
|---|---|
| Single-line | Anything after # on a line is a comment. |
| Multi-line | Multiple # lines, or wrap text in triple quotes """ … """. |
# compute area length = 5 breadth = 3 area = length * breadth # in square units """ This block explains the next section of the program. """
x = x + 1 # add 1 to x. Good comments explain why, not what.17 // 5?
print(2 ** 3 ** 2):
print()?
x = a + 5?
print(10 + 3 * 2)
Output: print(10 / 4) print(10 // 4)Output:
x = 5
y = x
x = 10
print(y)
Output: a, b = 3, 7
a, b = b, a
print(a, b)
Output: n = 10
n += 5
n *= 2
print(n)
Output: print("Hi" + "there") print("Hi" * 3)Output:
print(15 % 4) print(15 % 5)Output:
x = 7 print(x > 3 and x < 10) print(not x == 7)Output:
Each snippet has exactly one error. Mark the line number and write the corrected line.
1 1name = "Vivek" 2 print(1name)Wrong line: Correction:
1 total marks = 95
2 print(total marks)
Wrong line: Correction: 1 class = 11
2 print(class)
Wrong line: Correction: 1 x = 10 2 if x = 10: 3 print("ten")Wrong line: Correction:
1 Print("hello")
Wrong line: Correction: 1 10 = age
2 print(age)
Wrong line: Correction: =, == and += with one example each.
Each program should read input from the user (where required) and produce a clear output. Use a separate sheet if you need more space.
F = C * 9/5 + 32.
total = price + tax * 2. List each token with its type (keyword / identifier / literal / operator / punctuator).
// and %.)