Class 11 Computer Science Chapter 05 ยท 13 min read

Python Fundamentals

Unit 2 ยท Ch 5 Oct 10, 2026
Chapter Quiz Share

๐Ÿ Chapter 5: Python Fundamentals

๐Ÿ’ก How to use these notes

This chapter lays the foundation for the Python you will write in Class 11: the Python character set, tokens (keywords, identifiers, literals, operators and punctuators), the basic structure of a Python program, variables and assignments, and simple input and output. Pay particular attention to tokens, the rules for identifiers, and variables โ€” the later chapters build on them.


5.1 Introduction

Python is a high-level, interpreted, general-purpose programming language created by Guido van Rossum and first released in 1991. It is named after the British comedy series "Monty Python's Flying Circus" โ€” not the snake! ๐Ÿ

๐ŸŒŸ

Why Python?

Simple readable syntax, free & open source, platform independent, huge standard library, supports multiple paradigms

Feels like writing English
๐Ÿ“Œ

Key Facts

Creator: Guido van Rossum, Released: 1991, Type: Interpreted high-level language, Extension: .py

print("Hello")
๐Ÿง  Memory Trick

Python is an interpreted language, meaning the Python interpreter converts source code into machine code line by line at runtime, rather than compiling the whole program at once like C/C++.


5.2 Python Character Set

A character set is the set of valid characters that a language can recognize. A character is the smallest unit of a program.

๐Ÿ”ค

Letters

Uppercase and lowercase alphabets

Aโ€“Zaโ€“z
๐Ÿ”ข

Digits

Numeric digits 0 to 9

0โ€“9
โž•

Special Symbols

Symbols used in code for operations and punctuation

+ - * / % = ! & < > ( ) [ ] { }: ;
โฃ

Whitespaces

Characters that create space in code

Blank spacetabnewlinecarriage return
๐Ÿ“‹ Board Exam Tip

Python 3 supports the full Unicode character set, which means you can even use characters from Indian languages (like Bengali or Hindi) in strings and, in special cases, identifiers!


5.3 Tokens

The smallest individual unit in a Python program is called a Token (or lexical unit). The Python interpreter breaks every line of code into tokens before processing it.

flowchart TD
    A[Python Tokens] --> B[Keywords]
    A --> C[Identifiers]
    A --> D[Literals]
    A --> E[Operators]
    A --> F[Punctuators]
    class A normalNode
    class B,C,D,E,F tryNode

5.3.1 Keywords

Keywords are reserved words that have special meaning to the Python interpreter. They cannot be used as variable names, function names, or any other identifier.

๐Ÿ”‘ Rule

Python 3 has 35 keywords. All keywords are in lowercase except True, False, and None.

โœ…

Sample Keywords

False, None, True, and, as, break, class, continue, def, elif, else, for, if, import, in, is, not, or, return, while and more

35 keywords total
๐Ÿง 

Memory Trick

Keywords are VIPs of Python โ€” they already have a fixed job assigned

Can't hire if / for / class for a different role
โš  Common Mistake

print, input, len, range are NOT keywords โ€” they are built-in functions. Students often confuse this in exams! You can (though should not) use them as variable names.

5.3.2 Identifiers (Names)

An identifier is the name given to entities like variables, functions, classes, modules, etc.

โœ”๏ธ

Allowed

Start with a letter or underscore, followed by letters/digits/underscores, case-sensitive, any length

age_namestudent1
โŒ

Not Allowed

Cannot start with a digit, cannot contain special symbols or spaces, cannot be a keyword

1namena@memy nameclass
๐Ÿ’ก Board Exam Tip

A typical question gives a list of 4โ€“5 names and asks "Which are valid identifiers?" Always check: starts with digit? has space? has special symbol? is it a keyword?

5.3.3 Literals / Values

A literal is a raw data value directly written in the source code.

๐Ÿ”ข

Numeric Literals

Integer, float, and complex number values

103.143+5j
๐Ÿ”ค

String Literals

Text written inside quotes

'Hello'"Hi"'''multi-line'''
โœ…

Boolean Literals

Only two values, capital first letter

TrueFalse
๐ŸŒ€

Special Literal

Represents absence of a value

None

Numeric literals can further be written in different number systems:

System Prefix Example
Binary 0b or 0B 0b1010
Octal 0o or 0O 0o17
Decimal none 25
Hexadecimal 0x or 0X 0x1A
๐Ÿง  Memory Trick

A single character in Python (e.g. 'A') is not a separate data type โ€” it is simply treated as a string of length 1.

5.3.4 Operators

Operators are special symbols that carry out arithmetic or logical computation. The value(s) the operator acts on are called operands.

โž—

Arithmetic

Perform mathematical calculations

+ - * / // % **
โš–๏ธ

Relational

Compare two values

== != > < >= <=
๐Ÿ”—

Logical

Combine conditional statements

and or not
๐Ÿ“

Assignment

Assign or update values

= += -= *= /=
๐ŸŽฏ

Membership

Test membership in a sequence

in not in
๐Ÿชž

Identity

Compare memory identity

is is not
๐Ÿ“‹ Board Exam Tip

Difference between / and //:

  • / โ†’ True division โ†’ always gives a float โ†’ 7 / 2 โ†’ 3.5
  • // โ†’ Floor division โ†’ gives the floor (integer part) โ†’ 7 // 2 โ†’ 3

5.3.5 Punctuators

Punctuators are symbols used to organize sentence structure, indicate operations, and structure the program. Examples:

' " # \ ( ) [ ] { } @ , : . = ; += -= *= /=

๐Ÿง  Memory Trick

Punctuators are not the same as operators โ€” a punctuator's main role is structural (grouping, separating, terminating), even though some symbols overlap (like =).


5.4 Barebones of a Python Program

A minimal Python program has a very simple, indentation-based structure โ€” no semicolons, no curly braces required.

# This is my first Python program
print("Hello, World!")
๐Ÿ“

Indentation

Whitespace defines blocks of code instead of { }, must be consistent

Mandatory โ€” not optional
๐Ÿ’ฌ

Comments

Notes ignored by the interpreter

Single-line #multi-line ''' ... '''
๐Ÿงฉ

Statements

A logical line of code

Usually one statement per line
๐Ÿ” 

Case Sensitivity

Python treats uppercase and lowercase differently

Print โ‰  print
โš  Common Exam Mistake

Inconsistent indentation (mixing tabs and spaces) causes an IndentationError. Always use 4 spaces per indentation level consistently.

flowchart TD
    A[Start Program] --> B[Comment / Docstring]
    B --> C[Import Statements]
    C --> D[Statements with proper Indentation]
    D --> E[End Program]
    class A normalNode
    class B,C,D tryNode
    class E normalNode

5.5 Variables and Assignments

A variable is a named location in memory used to store a value that can change during program execution.

5.5.1 Creating a Variable

In Python, you don't need to declare a variable's type separately โ€” a variable is created the moment you assign a value to it.

age = 17          # integer variable
name = "Riya"     # string variable
height = 5.4      # float variable
๐Ÿ’ก How to use these notes

Unlike C/C++, Python has no separate declaration statement. Assignment is declaration!

5.5.2 Multiple Assignments

Python allows assigning values to multiple variables in different flexible ways:

Style Syntax Example
Same value to many variables a = b = c = value a = b = c = 10
Different values in one line a, b, c = v1, v2, v3 a, b, c = 10, 20, 30
Swapping without a third variable a, b = b, a a, b = b, a
๐Ÿ“‹ Board Exam Gold

Swapping two variables without a third variable using a, b = b, a can be asked as a one-mark or output-based question.

5.5.3 Variable Definition

A variable in Python is essentially a reference (name) bound to an object stored somewhere in memory. Python variables have:

Property Meaning
Name The identifier used to refer to the variable
Value The data currently stored
Type Determined automatically from the value assigned
id() Unique memory address identifier of the object
x = 10
print(id(x))    # shows the memory address of the object 10
print(type(x))  # shows <class 'int'>

5.5.4 Dynamic Typing

Python is a dynamically typed language โ€” the type of a variable is decided at runtime, based on the value assigned, and can change if reassigned.

x = 10        # x is int
x = "Hello"   # now x becomes str โ€” perfectly valid!
x = 3.14      # now x becomes float
๐Ÿง  Memory Trick

This is different from statically typed languages like C/C++/Java, where the data type of a variable is fixed at the time of declaration and cannot change.

๐Ÿง 

Memory Trick

Static is like a steel pipe with a fixed shape forever

Dynamic is like water taking the shape of its container
โš ๏ธ

Common Confusion

Dynamic typing does not mean "no data types"

Python is strongly typed too โ€” "5" + 5 still fails

5.5.5 l-value and r-value โฌ…๏ธ

In an assignment statement, the = sign does not mean "equal to". It means "evaluate the right side, then store the result in the name on the left".

          total   =   marks + 5
          โ”€โ”€โ”€โ”€โ”€       โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
         l-value       r-value
l-value r-value
Appears on the left of = Appears on the right of =
Must be something that can store a value โ€” a variable name Can be a literal, a variable or an expression that produces a value
e.g. x in x = 10 e.g. 10, a + b, y * 2
a = 10          # a is the l-value, 10 is the r-value
b = a * 2       # b is the l-value, a * 2 is the r-value
a = a + b       # the r-value (10 + 20) is worked out first, then stored in a
print(a, b)

Output:

30 20
โš  A literal or an expression can never be an l-value!

10 = x and a + b = 20 both give SyntaxError: cannot assign to literal / cannot assign to expression. The left side must always be a name.

๐Ÿ“‹ Board Exam Tip

"What are l-value and r-value? Give an example." โ€” 2-mark question! Answer: In an assignment statement, the l-value is the object on the left of = that receives a value (a variable name), and the r-value is the expression on the right of = whose value is assigned. In total = a + b, total is the l-value and a + b is the r-value.


5.6 Simple Input and Output

5.6.1 Reading Numbers

The built-in input() function always returns a string, even if the user types a number. To use it as a number, you must explicitly type-cast it.

age = input("Enter your age: ")       # age is a string, e.g. "17"
age = int(input("Enter your age: "))  # age is now an integer 17
height = float(input("Enter height: "))  # for decimal numbers
โš  Most common runtime error for beginners

Forgetting to type-cast input() before doing arithmetic โ†’ TypeError: unsupported operand type(s). Always wrap with int() or float() when expecting numbers!

๐Ÿ“ฅ

input() Key Facts

Always returns type str, takes an optional prompt message, pauses execution until Enter is pressed

input("Enter name: ")
๐Ÿ”

Type Casting Functions

Convert string input into the required type

int()float()str()

5.6.2 Output Through print() Function

The print() function displays output on the screen. It has several useful optional parameters:

print("Hello", "World", sep="-", end="!\n")
# Output: Hello-World!
Parameter Purpose Default
sep Separator between multiple values ' ' (space)
end What to print at the end '\n' (newline)
*objects One or more values to print โ€”

Modern f-strings are the CBSE-recommended way to combine text and variables:

name = "Amit"
marks = 95
print(f"{name} scored {marks} marks")
๐Ÿง 

Memory Trick

sep stands for spaces between words

end stands for ending punctuation of the print statement
๐Ÿ’ก How to use these notes

Practice predicting output for print() statements with custom sep and end โ€” these are typical 1โ€“2 mark output-based questions.


๐Ÿ“ Board Exam Practice Zone

1 Mark Questions

  1. Name the creator of Python.
  2. What will type(True) return?
  3. Is input() output a str, int, or float by default?
  4. What is the default value of sep in print()?
  5. Which of these is a valid identifier: 2fruit, _fruit, for, fruit#1?

2 Mark Questions

  1. Differentiate between Keywords and Identifiers with one example each.
  2. Differentiate between / and // operators with example.
  3. What is dynamic typing? Explain with an example.
  4. Write the rules for naming a valid Python identifier.

3 Mark Questions

  1. Write a program to swap two numbers without using a third variable.
  2. Explain any three types of literals in Python with examples.
  3. Predict the output:
a, b, c = 5, 10, 15
print(a, b, c, sep="*", end="#")

4 Mark / Output-Based Questions

  1. Identify errors, if any, in the following code and rewrite it correctly:
1name = input(Enter name)
Age = int(input("Enter age"))
print(Name, "is", age, "years old")
  1. Write a program that takes two numbers as input and prints their sum, difference, product, and floor division result, each on a separate line.
๐Ÿ”‘ Golden Rule for This Chapter

Whenever a question mixes keywords vs identifiers or type-casting of input(), examiners are testing whether you actually understand the rules, not just memorized examples. Always apply the rule step-by-step rather than guessing.


Take the Chapter 05 Quiz Custom Quiz
Learning Support

Need Help With This Chapter?

Save key topics for exam revision, ask questions to teachers, or submit content corrections.

Verified Doubts & Teacher Answers

Chapter 05 Quiz