Introduction to Python Notes – Class 9 AI (417) | Ultimate CBSE Guide
Scoring full marks in Python is easier than you think — here’s how!
These Introduction to Python Notes are specially designed for Class 9 AI students, presenting every concept in a simple and easy-to-understand manner. The notes help students grasp Python fundamentals quickly, build strong programming concepts, and gain the confidence needed to excel in exams.
These Python Class 9 Notes are not limited to theory alone. They include practical examples, solved programs, and multiple practice exercises for every topic, enabling students to develop their coding skills through hands-on learning. Whether you are preparing for examinations or learning Python for real-world applications, these notes provide the perfect balance of conceptual understanding and practical experience.
Start your Python journey today and make programming one of your strongest skills! 😊
Algorithm and Flowchart
How machine works?
Every machine, whether AI-enabled or not, performs tasks by following a set of instructions known as a program. These instructions guide the machine step by step to complete the task.
For example, a washing machine is designed to wash clothes and cannot perform unrelated tasks because it follows a predefined sequence of actions.
Write possible steps to wash cloths in a washing machine:
- Put the dirty clothes into the washing machine.
- Add detergent or washing powder.
- Close the machine door properly.
- Select the required washing mode.
- Fill the machine with water.
- Start the washing cycle.
- The machine agitates and cleans the clothes.
- Drain the dirty water.
- Rinse the clothes with clean water.
- Spin the clothes to remove excess water.
- Stop the machine after the cycle is complete.
- Remove the clean clothes from the machine.
Activity (Do It Yourself)
Write the possible steps to make Mango Juice.
How Are Programs Created for Machines?
- Identify the Task – Determine what the machine needs to do.
- Define the Goal – Clearly specify the main objective of the program.
- Break the Task into Smaller Steps – Divide the main task into manageable sub-tasks.
- Arrange the Steps Logically – Organize the steps in the correct sequence.
- Create an Algorithm – Write a step-by-step solution to achieve the goal.
- Draw a Flowchart – Represent the process visually to check the workflow.
- Write the Program – Convert the algorithm into instructions that the machine can understand and execute.
- Test and Improve – Check whether the program works correctly and make necessary improvements.
What is an Algorithm?
- An algorithm is a step-by-step set of instructions used to solve a problem or complete a task.
- It helps us perform tasks in the correct order to achieve the desired result.
- Before creating a computer program, we first write an algorithm to plan the solution.
An algorithm is a plan that tells us what to do, step by step.
Example: Algorithm to Make Mango Juice
- Wash the mangoes properly.
- Peel and cut the mangoes into pieces.
- Put the mango pieces into a mixer/blender.
- Add water and sugar as needed.
- Switch on the mixer and blend the ingredients until smooth.
- Pour the mango juice into a glass.
- Mango juice is ready.
Activity (Do It Yourself)
Write Algorithm for making instant noodles.
Write Algorithm for turning on a computer
Important Note
- Different people may write algorithms in different ways.
- The steps can vary, but the final goal remains the same.
- An algorithm should be clear, logical, and easy to follow.
What is a Flowchart?
- A flowchart is a graphical or pictorial representation of an algorithm.
- It uses different symbols, shapes, and arrows to represent the steps of a process.
- Flowcharts help us understand, analyze, and communicate a process more easily.
- They show the sequence of steps in a clear and visual manner, making complex tasks easier to understand.
Common Flowchart Symbols
| Symbol | Purpose |
| Terminal (Start/End) | Indicates the beginning or end of a flowchart. |
| Input/Output | Represents input given to or output received from a process. |
| Process | Represents an action, instruction, or operation. |
| Decision | Represents a condition that requires a Yes/No or True/False decision. |
| Arrow (Connector) | Shows the direction and flow of the process. |
How to make Flowchart to represent Algorithm
Example: Find the Area of a Rectangle
Algorithm
Step 1: Start.
Step 2: Input the length (L) of the rectangle.
Step 3: Input the width (W) of the rectangle.
Step 4: Calculate the area of the rectangle using Area = L × W.
Step 5: Display the area.
Step 6: End.
Flow Chart

Activity (Do It Yourself)
Write Algorithm and Flow Chart to:
- Add two numbers
- Check a number is even or odd
- Display largest among three numbers
- Check a number is prime or not
- How traffic signal works
Introduction to Python
What is Program?
A computer program is a set of instructions that tells a computer how to perform a specific task. These instructions are written by a programmer using a programming language.
What is Python?
- Python is a programming language created by Guido Van Rossum in 1991.
- It is widely used for developing software and websites, analyzing data, performing scientific calculations, and building Artificial Intelligence (AI) applications.
Why is Python So Popular? – Characteristics of Python
- Easy to Learn and Use
Python has a simple and easy-to-read syntax, making it beginner-friendly and easy to maintain. - Large Standard Library
Python provides many built-in libraries and functions that help solve a wide variety of problems quickly. - Interactive Mode
Python allows users to run and test code line by line, making learning, testing, and debugging easier. - Portable and Compatible
Python programs can run on different operating systems, such as Windows, Linux, and macOS, with little or no modification. - Extensible
Python can be combined with code written in other languages, allowing developers to add extra features and improve performance. - Database Support and Scalability
Python works with many databases and can be used to develop both small applications and large-scale projects.
Application of Python
- Web Development: Instagram, Spotify, Netflix
- Business Applications: Odoo, Triton, accounting software
- Games and 3D Graphics: Battlefield 2, The Sims 4, Blender
- Database Access: MySQL, PostgreSQL, Oracle databases
- Software Development: Buildbot, SCons, automated test scripts
- Desktop GUI Applications: Deluge, BitTorrent, desktop calculators
Common Programming Terms
1. Instruction – A single, direct command given to a computer to perform a specific action. For example – A single step in a cooking recipe (e.g., “Chop the onions”).
2. Program – A collection of instructions combined together to complete a specific task. For example – A complete recipe for baking a cake.
3. Software – A collection of multiple programs working together to perform various complex tasks on a computer. For example – An entire cookbook filled with different recipes for a full menu.
4. Source Code – The code written by a human programmer using a readable, high-level language (like Python, Java, or C++). Computers cannot run this code directly. For example – A letter written in English that needs to be translated into another language.
5. Machine Code – The final language that a computer’s hardware actually understands. It consists entirely of binary numbers (0s and 1s). For example – The native “brain language” of the computer chip.
6. Compiler – A translator program that takes the entire source code, translates it into machine code all at once, and saves it as a new file (like an .exe file) before running it. For example – Translating an entire English book into Spanish and printing the translated book before anyone reads it.
7. Interpreter – A translator program that reads, translates, and runs the source code line-by-line, instantly executing each action as it goes. For example – A live translator who listens to a speech and translates it out loud, sentence by sentence, in real-time.
Download and Installing Python for use
How to Download Python?
- Open a web browser and visit www.python.org.
- Click on the Downloads menu.
- Select your operating system, such as Windows, Linux/Unix, macOS, or Android.
- For example, if you are using Windows, click on Windows.
- Download the appropriate installer, such as Windows Installer (64-bit) or Windows Installer (32-bit).
- Python will be downloaded to your computer and will be ready for installation.

How to Install Python?
- Double-click the Python installer that you have downloaded.
(For example, Python 3.14.5 (64-bit)). - On the installation window, select Add Python.exe to PATH.
- Click Install Now.
- If a User Account Control message appears, click Yes to allow Windows to install Python.
- Wait for the installation process to complete.
- Python and IDLE will be installed on your computer and ready to use.

Python IDE (IDLE)
- When Python is installed on a computer, an IDE called IDLE is also installed.
- IDLE (Integrated Development and Learning Environment) is the standard Python development environment. It provides a single interface to write, run, edit, and debug Python programs.
- IDLE makes programming easier, especially for beginners.
How to Start Python IDLE?
- Click Start Menu.
- Search for IDLE.
- Click IDLE (Python 3.x).
- The IDLE window opens.

Note: When we open IDLE, it starts in Interactive Mode by default, and the window that opens is called the Python Shell. It allows us to enter Python commands and see the results immediately.
Working Modes of Python
Python can be used in two modes:
- Interactive Mode
- Script Mode
Interactive Mode
- Interactive Mode opens by default when IDLE is started.
- In this mode, commands are entered in the Python Shell.
- Python executes each command immediately and displays the result.
- It is convenient for learning Python, performing quick calculations, and testing small pieces of code.

Script Mode
- In this mode, a complete program is written in the Editor Window.
- The program is saved as a Python file (.py).
- The entire program is executed at once when it is run.
- It is convenient for creating longer and more complex programs.
- To work with Script mode, click on File -> New File
Working in Script Mode
- Click File → New File to open a new Editor Window.
- Type the Python statements required to solve the problem.
- Save the program using File → Save and give it a meaningful name.
- Run the program using Run → Run Module.
- The output of the program will be displayed in the Python Shell.

Python Script/Program: Python statements written in a particular sequence to solve a problem is known as Python Script/Program.
Understanding First Python Program

- # Python First Program is a comment used to describe the purpose of the program. Comments are ignored during program execution.
- print(“cbsesolutions.in”) displays the text cbsesolutions.in on the screen.
- print() is a built-in Python function used to display output.
- name = “Sanjay” creates a variable named name and stores the string value “Sanjay” in it.
- print(name) displays the value stored in the variable name.
- X = 23 and Y = 34 assign the integer values 23 and 34 to the variables X and Y respectively.
- print(“Total =”, X + Y) calculates the sum of X and Y and displays the result along with the text “Total =”.
- The + operator is an arithmetic operator used to add two numbers.
Components of Python Program

Python Statements
A statement is an instruction written in a Python program that tells the computer to perform a specific task. Python executes statements one by one to produce the desired output.
Examples:
name = “Sanjay”
print(name)
X = 23
Multi-line Statements
Sometimes, long statements can be written across two or more lines. Such statements are called multi-line statements. Python allows multi-line statements using:
- Continuation character (\)
- Parentheses (())
- Square brackets ([])
- Braces ({})
- Semicolon (;)
Example:
total = 10 + 20 + 30 + \
40 + 50
Output:
150
In the above example, the statement is written on two lines using the continuation character (\).
Example:
message = (“Artificial Intelligence ” \
“is an exciting field.”)
print(message)
Output:
Artificial Intelligence is an exciting field.
| Type of Multi-line Statement | Usage | Example |
| Using Continuation Character (\) | Used to continue a statement on the next line. | result = 10 + 20 + 30 + \ 40 + 50 print(result) Output: 150 |
| Using Parentheses () | Statements inside parentheses can span multiple lines without using \. | total_marks = ( 85 + 90 + 88 + 92 + 95 ) print(total_marks) Output:450 |
| Using Square Brackets [] | Lists can be written across multiple lines for better readability. | subjects = [ “English”, “Maths”, “Science”, “Computer” ] print(subjects) Output: [‘English’, ‘Maths’, ‘Science’, ‘Computer’] |
| Using Braces {} | Sets or dictionaries can be spread across multiple lines. | colors = { “Red”, “Green”, “Blue”, “Yellow” } print(colors) Output: {‘Red’, ‘Green’, ‘Blue’, ‘Yellow’} |
| Using Semicolons (;) | Multiple statements can be written on a single line. | name = “Aman”; age = 15; grade = “10th” print(name, age, grade) Output: Aman 15 10th |
Comments in Python
- Comments are pieces of text written inside a program.
- They are used to explain what a program or a block of code does.
- Comments do not affect the execution or output of the program.
- In Python, comments start with the # (hash) symbol.
Single-line Comment
A single-line comment is used to write a short note or explanation on a single line. It begins with the # symbol.
Example:
# Displaying a welcome message
print(“Welcome to Python”)
Output:
Welcome to Python
Multi-line Comment
A multi-line comment is used when the explanation is too long to fit on a single line. In Python, multi-line comments can be written using triple quotes (”’ ”’ or “”” “””).
Example:
“””
This program displays
a welcome message
on the screen.
“””
print(“Welcome to Python”)
Output:
Welcome to Python
Python Keywords
- Keywords are reserved words that have special meanings and predefined purposes in Python.
- Keywords cannot be used as variable names or identifiers.
- Python is case-sensitive, so keywords must be written exactly as defined.
Common Python Keywords

Identifiers
An identifier is a name given to entities like class, functions, variables, etc. It helps to differentiate one entity from another.
Rules for Identifiers:
- Composition: Identifiers can be a combination of letters in lowercase (a to z) or uppercase (A to Z) or digits (0 to 9) or an underscore _.
- Starting Character: An identifier cannot start with a digit. 1variable is invalid, but variable1 is perfectly fine.
- Keywords: Keywords cannot be used as identifiers.
- Special Symbols: We cannot use special symbols like !, @, #, $, % etc. in our identifier.
- Length: Identifier can be of any length.
- Case Sensitivity: Python is a case-sensitive language. This means Variable and variable are not treated the same.
- Meaningful Naming: Always name identifiers so that they make sense. While a statement like c = 10 is valid, writing count = 10 makes much more sense and makes it easier to figure out what the code does, even when you look back at it after a long gap.
- Multi-word Separation: Multiple words within a name can be separated using an underscore—for example, this_is_a_long_variable.
Variables
A variable is a named memory location used to store data in a program. It acts like a container that holds a value, which can be changed later if needed.
Example:
x = 42
y = 35
In the above example:
- x and y are variable names.
- 42 and 35 are the values stored in the variables.
- Python reserves memory to store these values.
- The values can be used or changed later in the program.
Note: The assignment operator (=) is used to assign a value to a variable.
Example:
x = 42
Here, the value 42 is assigned to the variable x.
How to change value of a variable?
name = “cbsesolutions.in”
print(name)
name = “best for cbse skill education”
print(name)
Output:
cbsesolutions.in
best for cbse skill education
How to Assign Same value to Different variables
x = y = z = 10
print(x,y,z)
Output:
10 10 10
In the above example:
The statement x = y = z = 10 assigns the value 10 to all three variables: a, b, and c.
All variables refer to the same value (10) in memory.
How to Assigning Different Values to Different Variables
x, y, z = 10, 20, 30
print(x,y,z)
Output:
10 20 30
In the above example:
The statement x,y,z = 10,20,30 assigns x = 10, y = 20, z = 30 (values are assigned in order)
Input and Output in Python
How to Input a value in a variable in Python
- In Python, the input() function is used to take input from the user through devices like a keyboard.
- By default, all input values are treated as strings (text).
- If required, we can convert the input into other data types like int, float, etc., using type conversion functions.
Examples
name = input(“Enter your full name: “) # stored as string
marks = input(“Enter your marks: “) # stored as string
marks = int(input(“Enter your marks: “)) # converted to int
Output in Python
- Python uses the print() function to display output on the screen.
- It can display text, variables, or the result of expressions.
- The expression is evaluated first, and then the result is shown as output.