CBSE Class 9 AI Unit 5 Introduction to Python Notes (2026–27) | Complete Study Notes with Programs
Class 9 · Artificial Intelligence
CBSE Class 9 Artificial Intelligence Notes – Unit 5: Introduction to Python (2026–27)
Python is one of the most popular programming languages in the world and serves as the foundation of modern Artificial Intelligence, Machine Learning, Robotics, Data Science, Web Development, and Automation. It is known for its simple syntax, readability, and ease of learning, making it the ideal programming language for beginners.
In this unit, you will learn the basics of Python programming, understand how Python programs are written, explore different programming modes, and study fundamental concepts such as input/output functions, variables, operators, data types, control statements, loops, and lists.
Topics Covered
- Introduction to Python
- Applications of Python
- Interactive Mode and Script Mode
- Input and Output Functions
- Variables
- Data Types
- Type Conversion
- Arithmetic Operators
- Expressions
- Flow of Control
- Conditional Statements
- Loops
- Python Lists
- Suggested Practical Programs
1. Introduction to Python
Python is a high-level, interpreted programming language that is easy to read, easy to write, and easy to understand. It is one of the most widely used programming languages for developing Artificial Intelligence applications because of its simplicity and powerful built-in libraries.
Python is considered a beginner-friendly programming language since programmers can write complex programs using fewer lines of code compared to many other programming languages.
Features of Python
- Easy to learn and understand.
- Simple and readable syntax.
- Requires fewer lines of code.
- Supports modular programming.
- Free and open-source.
- Portable across different operating systems.
- Large collection of libraries for AI and Machine Learning.
Why is Python Popular?
Python has become the preferred programming language for Artificial Intelligence because developers can quickly create powerful applications without writing lengthy code.
Its modular nature allows programmers to reuse existing code, reducing development time and improving productivity.
Example
Instead of writing the same calculations repeatedly, programmers can create reusable modules or functions and use them whenever needed.
Applications of Python
According to the CBSE curriculum, Python is used in numerous fields including:
| Application Area | Example |
|---|---|
| Artificial Intelligence & Machine Learning | Prediction systems, Recommendation engines, Chatbots. |
| Web Development | Building websites and web applications. |
| Software Development | Desktop applications and utilities. |
| Mobile Applications | Developing smartphone applications. |
| Robotics | Programming intelligent robots. |
| Internet of Things (IoT) | Smart home automation. |
| Game Development | Educational and interactive games. |
Programming Modes in Python
Python supports two different programming modes:
1. Interactive Mode
Interactive Mode allows programmers to execute one statement at a time and immediately view the output.
Uses
- Learning Python.
- Testing small programs.
- Performing calculations.
- Checking syntax quickly.
Example
>>> 20 + 30 50
2. Script Mode
Script Mode is used to write complete Python programs, save them as files, and execute them whenever required.
Example
print("Welcome to Python")
print("Welcome to Artificial Intelligence")
Python program files are saved with the .py extension.
Interactive Mode vs Script Mode
| Interactive Mode | Script Mode |
|---|---|
| Runs one statement at a time. | Runs complete programs. |
| Output appears immediately. | Output appears after executing the file. |
| No need to save the program. | Program is saved permanently. |
| Suitable for testing. | Suitable for developing applications. |
2. Input and Output Functions
Programming involves communication between the user and the computer. Python provides two basic functions for this purpose.
print() Function
The print() function is used to display output on the screen.
Syntax
print("message")
Example
print("Hello Students")
print("Welcome to Python")
Output
Hello Students Welcome to Python
The handbook also demonstrates using multiple print() statements to create star (*) patterns.
Example
print("*")
print("**")
print("***")
print("****")
input() Function
The input() function accepts data from the user through the keyboard.
Syntax
variable = input("Message")
Example
name = input("Enter your name : ")
print(name)
Real-Life Example
Suppose a school wants students to enter their names before starting an online quiz.
student = input("Enter Student Name : ")
print("Welcome", student)
Similarly, the handbook suggests using input() to accept marks from students for calculating averages.
Key Points
- Python is one of the easiest programming languages to learn.
- It is the most widely used language for Artificial Intelligence.
- Python programs can be executed using Interactive Mode or Script Mode.
- print() displays output.
- input() accepts data from the user.
- Python files are saved with the .py extension.
3. Variables, Operators and Data Types
Every Python program works with data. To store, manipulate and process this data, Python provides variables, data types, operators and expressions. These are the building blocks of every Python program.
Variables
A variable is a named memory location used to store data values. You can think of a variable as a container that stores information which can be used or changed later in the program.
Syntax
variable_name = value
Examples
age = 15 name = "Riya" marks = 92
Here:
- age stores an integer value.
- name stores text.
- marks stores numerical marks.
Rules for Naming Variables
- Variable names may contain letters, digits and underscores (_).
- The first character must be a letter or underscore.
- Spaces are not allowed.
- Python keywords cannot be used as variable names.
- Variable names are case-sensitive.
Valid Variable Names
student student_name age1 marks totalMarks
Invalid Variable Names
1student student name class my-name
Data Types in Python
A data type specifies the kind of value stored in a variable.
According to the CBSE syllabus, Python mainly uses the following data types:
| Data Type | Description | Example |
|---|---|---|
| Integer (int) | Whole numbers without decimal points. | 10, 250, -45 |
| Float | Numbers containing decimal values. | 3.14, 78.5, 0.25 |
| String (str) | Sequence of characters enclosed in quotes. | "Python", "AI", "Sunil" |
Examples
roll = 25 percentage = 92.5 school = "Subodh Public School"
Type Conversion
The input() function always accepts data as a string. Therefore, whenever numerical calculations are required, the entered value must first be converted into the required data type.
Common Conversion Functions
| Function | Purpose |
|---|---|
| int() | Converts data into Integer. |
| float() | Converts data into Float. |
| str() | Converts data into String. |
Example
marks = int(input("Enter Marks : "))
Now the entered value can participate in mathematical calculations.
Arithmetic Operators
Operators perform mathematical calculations on variables and values.
| Operator | Meaning | Example |
|---|---|---|
| + | Addition | 10 + 5 = 15 |
| - | Subtraction | 10 - 5 = 5 |
| * | Multiplication | 10 * 5 = 50 |
| / | Division | 10 / 5 = 2.0 |
| ** | Power (Exponent) | 2 ** 3 = 8 |
Example Program
a = 20 b = 10 print(a + b) print(a - b) print(a * b) print(a / b) print(a ** 2)
Expressions
An expression is a combination of variables, constants and operators that produces a value.
Example
Area = Length * Breadth
Here,
- Length and Breadth are variables.
- * is the multiplication operator.
- The complete statement forms an expression.
Real-Life Example – Area of a Rectangle
length = int(input("Enter Length : "))
breadth = int(input("Enter Breadth : "))
area = length * breadth
print("Area =", area)
Real-Life Example – Average Marks
The handbook suggests accepting marks using the input() function and calculating the average.
m1 = int(input("Enter Marks 1 : "))
m2 = int(input("Enter Marks 2 : "))
m3 = int(input("Enter Marks 3 : "))
average = (m1 + m2 + m3) / 3
print("Average =", average)
Quick Revision
- A variable stores data.
- Python supports Integer, Float and String data types.
- input() always returns a String.
- Use int() or float() before performing calculations.
- Arithmetic operators perform mathematical operations.
- An expression combines variables and operators to produce a result.
4. Flow of Control and Conditions
Normally, Python executes program statements one after another from top to bottom. However, many real-life situations require the program to make decisions or repeat certain tasks. This is called the Flow of Control.
Flow of Control determines the order in which statements are executed in a Python program.
Why is Flow of Control Needed?
Imagine a school ERP system that checks whether a student has passed or failed.
The program cannot display both messages. It must first check the marks and then decide which message should be displayed.
Similarly, a traffic signal AI decides whether vehicles should stop or move based on the signal colour.
Conditional Statements
Conditional statements allow Python to make decisions based on specified conditions.
Python provides three important conditional statements:
- if
- if...else
- if...elif...else
1. if Statement
The if statement executes a block of code only if the given condition is True.
Syntax
if condition:
statement
Example
age = 20
if age >= 18:
print("Eligible to Vote")
2. if...else Statement
The if...else statement executes one block when the condition is True and another block when the condition is False.
Syntax
if condition:
statement1
else:
statement2
Example (Handbook Example)
age = int(input("Enter Age : "))
if age >= 18:
print("Eligible to Vote")
else:
print("Not Eligible")
3. if...elif...else Statement
When multiple conditions need to be checked, Python uses the if...elif...else statement.
Syntax
if condition1:
statement
elif condition2:
statement
else:
statement
Example
marks = int(input("Enter Marks : "))
if marks >= 90:
print("Grade A")
elif marks >= 75:
print("Grade B")
elif marks >= 50:
print("Grade C")
else:
print("Needs Improvement")
Real-Life Example
Schools often award certificates based on marks obtained by students. The computer checks different ranges of marks before displaying the appropriate grade.
Iterative Statements (Loops)
Sometimes the same task must be performed repeatedly. Instead of writing the same statement many times, Python provides loops.
A loop repeatedly executes a block of code until a specified condition becomes False.
Types of Loops
- for Loop
- while Loop
1. for Loop
The for loop is used when the number of repetitions is already known.
Syntax
for variable in range():
statement
Example
for i in range(1,6):
print(i)
Output
1 2 3 4 5
Printing First 10 Even Numbers
The handbook mentions using a for loop to print even numbers.
for i in range(2,21,2):
print(i)
2. while Loop
The while loop repeats a block of code as long as a condition remains True.
Syntax
while condition:
statement
Example
count = 1
while count <= 5:
print(count)
count = count + 1
Difference between for Loop and while Loop
| for Loop | while Loop |
|---|---|
| Used when number of repetitions is known. | Used when repetitions are unknown. |
| Works with range(). | Works using a condition. |
| Simpler for counting. | Better for condition-based repetition. |
5. Python Lists
A List is an ordered collection used to store multiple values inside a single variable.
Lists are enclosed within square brackets [ ].
Example
students = ["Aman","Riya","Neha","Rahul"]
Advantages of Lists
- Store multiple values in one variable.
- Easy to modify.
- Items remain in order.
- Supports indexing.
List Indexing
Each element in a list has an index (position number).
Positive Indexing
| Index | 0 | 1 | 2 | 3 |
|---|---|---|---|---|
| Value | Aman | Riya | Neha | Rahul |
Negative Indexing
| Index | -4 | -3 | -2 | -1 |
|---|---|---|---|---|
| Value | Aman | Riya | Neha | Rahul |
Common List Operations
1. append()
Adds one new item at the end of the list.
students.append("Ankit")
2. extend()
Adds multiple items to the end of the list.
students.extend(["Karan","Pooja"])
3. remove()
Removes a specified item from the list.
students.remove("Neha")
4. del Statement
Deletes an item using its index.
del students[2]
5. len()
Returns the total number of items in a list.
print(len(students))
6. sort()
Arranges list elements in ascending or alphabetical order.
students.sort()
Suggested Practical Programs (CBSE Handbook)
Students should practise the following programs mentioned in the handbook:
- Calculate Simple Interest using Principal, Rate and Time.
- Calculate Area and Perimeter of a Rectangle.
- Create a Science Quiz List and perform add/remove operations.
- Find the Sum of all Numbers stored in a List using a Loop.
Complete Revision Notes
- Flow of Control determines program execution order.
- if executes code when the condition is True.
- if...else chooses between two alternatives.
- if...elif...else checks multiple conditions.
- for loop is used when repetitions are known.
- while loop repeats until the condition becomes False.
- A List stores multiple values inside one variable.
- Lists use square brackets [ ].
- Positive indexing starts from 0.
- Negative indexing starts from -1.
- append() adds one item.
- extend() adds multiple items.
- remove() deletes a value.
- del deletes an item using its index.
- len() counts list items.
- sort() arranges list elements.
Exam Tips
- Remember the difference between Interactive Mode and Script Mode.
- Learn the syntax of print() and input().
- Know the three Python data types prescribed in the syllabus.
- Practice type conversion using int().
- Revise arithmetic operators and expressions.
- Understand the difference between if, if...else, and if...elif...else.
- Practice both for and while loops.
- Memorise common list functions: append(), extend(), remove(), len() and sort().
- Practice the four suggested practical programs from the handbook.
Conclusion
Python is an easy-to-learn programming language and forms the backbone of Artificial Intelligence. By understanding variables, data types, operators, control statements, loops and lists, students build a strong programming foundation required for developing intelligent applications in higher classes. Regular practice of simple Python programs will strengthen logical thinking and problem-solving skills.