Chapter 8 — Getting Started with Python

Easy-language Notes · Part 1 of 2 (intro · first program · tokens)
REVISION NOTES
Class XI · Computer Science (083)
Sheet 1 (Front)

1. What is Python? · Features

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.

Python reads almost like plain English. print("Hello") simply prints "Hello". This is why it is the first language taught in most schools and colleges today.

Main Features

  • Simple & readable — uses indentation, no braces or semicolons clutter.
  • Interpreted — runs line by line; you don't compile first.
  • Free & open source — download and use without paying.
  • Cross-platform — same code runs on Windows, macOS, Linux, Android.
  • Dynamically typed — no need to declare a variable's type.
  • Object-oriented — supports classes and objects.
  • Huge standard library — ready-made modules (math, datetime, random, csv, etc.).
  • Extensible — can be combined with C/C++ code.

Where Python is used 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.

Limitations

  • Slower than compiled languages like C / C++.
  • Uses more memory.
  • Not the first choice for mobile-app development.
Exam-ready definition: "Python is a high-level, interpreted, general-purpose, object-oriented programming language created by Guido van Rossum in 1991."

2. First Program · Execution Modes

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!

Two Ways to Run Python Code

ModeHow 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.
ScriptWrite the full program in a .py file using an editor (IDLE, VS Code) and run with python file.py. Good for big reusable programs.
Interactive shell — results auto-print:
>>> 2 + 3
5
>>> print("hi")
hi
>>> "py" * 3
'pypypy'
>>> is the prompt — you don't type it.
Script (saved as greet.py):
name = "Vivek"
print("Hello", name)
print("Welcome to Class XI")
Run it: python greet.py. Both prints execute in order.
In interactive mode, just typing a value (e.g. 2 + 3) shows the result. In script mode, you must use print() to see anything — the shell does not auto-display.
Use the shell for quick experiments and to learn new features. Use scripts for the actual assignments and project work that need to be saved and submitted.

3. Character Set · Tokens

The character set is the collection of symbols Python understands when you write code:

  • Letters: A–Z, a–z
  • Digits: 0–9
  • Special symbols: + - * / % = < > ( ) [ ] { } : ; , . " ' # \ _ & | ! ? @
  • Whitespace: space, tab, newline
  • Other Unicode characters in strings (Hindi, emoji-as-text, etc.).

What is a Token?

A token is the smallest meaningful piece of Python code — a "word" of the language. Python splits your code into tokens before running it.

Five Types of Tokens

TypeExamples
Keywordsif, else, for, while, def, return, True, False, None, in, and, or, not, import
Identifiersmarks, total_score, _x1, RollNo — names you give
Literals10, 3.14, "hi", True, None — fixed values written as-is
Operators+ - * / // % ** == != > < and or not =
Punctuators( ) [ ] { } , : ; . — help group code
In the line x = 5 + 3:
  • x → identifier
  • = → operator (assignment)
  • 5, 3 → literals (numbers)
  • + → operator
Five tokens in total.
In if x > 0: — if is a keyword, x is an identifier, > is an operator, 0 is a literal, : is a punctuator. Five tokens here too.
A quick way to count tokens: split the line by spaces and operators — each piece is one token. Spaces and tabs themselves are not tokens.

4. Keywords · Identifiers · Literals

Keywords (reserved words)

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

Keywords are case-sensitive. True, False, None begin with a capital letter. Writing true or FALSE is wrong — gives NameError.

Identifiers (names)

An identifier is the name you give to a variable, function, class or module.

Rules:

  • Allowed characters: 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 (@ # $ %, hyphen).
  • Case-sensitive: Marks and marks are two different names.
  • No length limit (but keep them readable).
Valid: name, total_marks, _count, mark1, RollNo, x_2y.
Invalid: 1name (digit start), total marks (space), class (keyword), my-var (hyphen), price$ (dollar).

Literals (fixed values)

A literal is a value written directly in the program. Six common types:

TypeExamples
Integer10, -3, 0, 1000000
Float3.14, -0.5, 2.0, 1.5e3
Complex2 + 3j, -4j
String"hello", 'Python', "123"
BooleanTrue, False
SpecialNone (means "no value")
Strings can be in single or double quotes — both work. Use double when the string contains a single quote: "It's fine". Use triple quotes """ """ for multi-line strings.

Chapter 8 — Getting Started with Python

Easy-language Notes · Part 2 of 2 (keywords · identifiers · literals · operators · variables)
REVISION NOTES
Class XI · Computer Science (083)
Sheet 1 (Back)

5. Operators · Punctuators

Common Operator Groups

GroupSymbols
Arithmetic+   -   *   /   //   %   **
Relational==   !=   >   <   >=   <=
Logicaland   or   not
Assignment=   +=   -=   *=   /=   //=   %=   **=
Identityis   is not
Membershipin   not in
Bitwise&   |   ^   ~   <<   >>
Difference between /, //, % 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)
Compound assignment:
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
Membership and identity:
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)

Punctuators

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.

Don't confuse = (assignment) with == (equality test). x = 5 stores 5; x == 5 asks "is x equal to 5?".

6. Variables · L/R-Value · Comments

Variables — the Box Model

A variable is a name that refers to a value. The statement x = 5 reads as "name x points to value 5".

Imagine a labelled box. 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

L-value and R-value

In an assignment L = R:

  • L-value — the thing on the left of =. Must be a name where a value can be stored.
  • R-value — the thing on the right. The value (or expression) that gets evaluated and assigned.
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).

Multiple Assignment Shortcuts

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 — making code readable

Comments are notes for humans — Python ignores them.

StyleHow to write
Single-lineAnything after # on a line is a comment.
Multi-lineMultiple # 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.
"""
Triple-quoted strings used as "comments" are technically string literals that Python evaluates and discards. They are also used as docstrings — the first statement inside a function or class to describe it.
Avoid comments that just repeat the code — e.g. x = x + 1 # add 1 to x. Good comments explain why, not what.

Chapter 8 Worksheet — Getting Started with Python

Total: 50 marks  |  Time: 75 min
Name: Class/Sec: Roll No.: Date:

Section A — Multiple Choice (1 × 10 = 10)

  1. Who created Python?
    (a) Dennis Ritchie(b) James Gosling(c) Guido van Rossum(d) Bjarne Stroustrup
  2. Which is not a feature of Python?
    (a) Compiled(b) Interpreted(c) Open source(d) Cross-platform
  3. Which one is a valid identifier?
    (a) 1value(b) my-name(c) _total(d) class
  4. What is the result of 17 // 5?
    (a) 3.4(b) 3(c) 2(d) 3.5
  5. Which one is NOT a Python keyword?
    (a) for(b) None(c) integer(d) elif
  6. Which of the following is a literal?
    (a) total(b) "hello"(c) +(d) :
  7. Which symbol begins a single-line comment?
    (a) //(b) /*(c) #(d) --
  8. Output of print(2 ** 3 ** 2):
    (a) 64(b) 512(c) 6(d) Error
  9. Which mode shows a result without using print()?
    (a) Script mode(b) Compile mode(c) Interactive mode(d) Debug mode
  10. How many tokens are in the line x = a + 5?
    (a) 3(b) 4(c) 5(d) 6

Section B — Find the Output (1 × 8 = 8)

  1. print(10 + 3 * 2)
    Output:
  2. print(10 / 4)
    print(10 // 4)
    Output:
  3. x = 5
    y = x
    x = 10
    print(y)
    Output:
  4. a, b = 3, 7
    a, b = b, a
    print(a, b)
    Output:
  5. n = 10
    n += 5
    n *= 2
    print(n)
    Output:
  6. print("Hi" + "there")
    print("Hi" * 3)
    Output:
  7. print(15 % 4)
    print(15 % 5)
    Output:
  8. x = 7
    print(x > 3 and x < 10)
    print(not x == 7)
    Output:

Section C — Find the Error (1 × 6 = 6)

Each snippet has exactly one error. Mark the line number and write the corrected line.

  1. 1  1name = "Vivek"
    2  print(1name)
    Wrong line:   Correction:
  2. 1  total marks = 95
    2  print(total marks)
    Wrong line:   Correction:
  3. 1  class = 11
    2  print(class)
    Wrong line:   Correction:
  4. 1  x = 10
    2  if x = 10:
    3      print("ten")
    Wrong line:   Correction:
  5. 1  Print("hello")
    Wrong line:   Correction:
  6. 1  10 = age
    2  print(age)
    Wrong line:   Correction:

Section D — Short Answer (2 × 5 = 10)

  1. Differentiate between interactive mode and script mode with one example each.
  2. What is a token? Name any three types of tokens in Python.
  3. State any four rules for naming a Python identifier.
  4. Differentiate =, == and += with one example each.
  5. What is the difference between a keyword and an identifier? Give one example of each.

Chapter 8 Worksheet — (continued)

Sheet 2 (Back)

Section E — Code Tasks (16 marks)

Each program should read input from the user (where required) and produce a clear output. Use a separate sheet if you need more space.

  1. (2) Write a Python program that prints your name, class and school on three separate lines.
  2. (3) Write a Python program that reads the length and breadth of a rectangle and prints its area and perimeter.
  3. (3) Write a Python program that reads two integers a and b and swaps their values without using a third variable. Print both values before and after.
  4. (3) Write a Python program that reads a temperature in Celsius and prints the equivalent value in Fahrenheit using F = C * 9/5 + 32.
  5. (2) Identify the tokens in the statement total = price + tax * 2. List each token with its type (keyword / identifier / literal / operator / punctuator).
  6. (3) Write a Python program that reads a 3-digit number and prints the sum of its digits. (Hint: use // and %.)