GRADE 9&10- Python
GRADE 9&10- Python
Interactive Mode
(Immediate
Python Mode)
working
Ways
Script
Mode
The default installationof CPython comes with
Interpreter, Python IDLE and pip(package installer). To
Python
work in either interactive mode or script we need to
open Python IDLE
>>> 20(+>>> )
prompt (command give by user)
For
30 e.g if you type 20 + 30(output
in from of IDLE by
prompt
given
50 the above example
From python)
you can see than at >>>
we have to just give the command to execute and
python we execute it if it is error free otherwise
gives an error.
(
)
( ) )
( )
(
)
print
(“Hello”)
Script Mode – multiple commands can be saved in a
file as a
program and then we can execute the entire program
we type Python program in a file and then use the
interpreter to execute the content from the file.
Working in interactive mode is convenient for beginners
and for testing small pieces of code, as we can test
them immediately. But for coding more than few lines,
we should always save our code so that we may
modify and reuse the code
In Python IDLE :
Click File New
In new window type the commands you want to save
in program
For example:
print(“Hello World!”)
)
print
(“Hello”)
VARIABLES
CONSTANTS
A constant refers to a data value that remains
fixed. Its value does not change during the
execution of the program. They are of 2 types
Numeric and String constants.
Rules for Naming Variables in Python:
1. Start with a letter or underscore (_)
o Valid: name, _age
o Invalid: 1value
2. Can include letters, digits, and underscores
o Valid: student1, marks_total
3. Cannot start with a number
o ❌ Invalid: 2score
4. Cannot use Python keywords (like if, for, def, etc.)
o ❌ Invalid: class = "Math"
5. Are case-sensitive
o Name and name are different
6. Cannot contain special characters
o ❌ Invalid: total$, marks%
Good Naming Practices:
•Use meaningful names: marks_obtained, student_name
•Use underscores to separate words: total_marks
•Avoid single-letter names unless needed (like i in a loop)
Ex:
X= input(“Enter your name:”)
INTEGER
DATA TYPES FLOAT
STRING
BOOLEAN
“I can hold words, numbers, or nothing at all.
Sometimes I change, sometimes I don’t.
I help your programs store and play –
What am I?
LEARNING OBJECTIVES
end of this lesson, students will be able to:
tify and explain Python data types: None, String, Tup
d escape characters.
e and execute simple Python programs using these ty
erentiate
· between mutable and immutable data types
CONTENT/TOPIC:
DATA TYPES
String
Tuple
List
Escape Sequence Characters
DATA TYPES -
Example
Data Type Description Code Output
Represents
None absence of x = None print(x) → None
value
Text, written in
String quotes s = "Hello" print(s) → Hello
Example:1
A form where a user hasn’t entered their phone number yet.
phone_number = None # User skipped the field
print("Phone number:", phone_number)
Output:
Phone number: None
Example:2
x = None
print(x) # Output: None
print(type(x)) # Output: <class 'NoneType'>
String – Text Data
A string type of data (str) is used to store a sequence of characters and
numbers in single quotes or double quotes.
For multiline strings, use triple single quotes or triple double quotes.
Example:1
To store a student's name and welcome message.
student_name = "Aarav"
message = "Welcome to Python class, " + student_name + "!"
print(message)
Output:
Welcome to Python class, Aarav!
Example:2
text = """This is a
multiline string
in Python."""
print(text)
Output: This is a
multiline string
in Python.
Escape Sequence Characters -
Escape sequence characters are non printable characters which are used
for formatting the text in output. It is represented with a backslash.
Escape sequences like \n (new line) and \t (tab space) improve the
readability of output.
Example:1
print("Student Report:\nName:\tAnanya\nGrade:\t9")
Output:
Student Report:
Name: Ananya
Grade: 9
Escape Sequence Characters -
print("Line1\vLine2")
\v Vertical Tab Line1
Line2
Bell/Alert (makes a beep
\a sound) May beep on terminal
Activity: “Poem or Poster” Using Multiline Strings
Objective:
Students will create their own poster, poem, or message using multiline
strings in Python, helping them:
• Understand triple quotes (''' or """)
• Format output across multiple lines
• Write in your notebook
• Use triple quotes to create a string that includes:
• A title (centered or highlighted)
• A message, poem, or quote spread across 3–5 lines
Activity: 1 “Poem or Poster” Using Multiline Strings
Example 1: A Motivational Poem
message = """
***************************
BELIEVE IN YOURSELF
***************************
Every coder was once a beginner.
With practice, bugs turn into breakthroughs.
Keep typing, keep trying!
"""
print(message)
Example 2: A Healthy Eating Poster
poster = """
=========================
EAT SMART, STAY STRONG
=========================
Add greens to every plate
Drink 8 glasses of water
An apple a day keeps the doctor away
"""
print(poster)
List :
What is a List?
• Mutable (can be changed)
• Ordered collection
• Allows duplicates
• Defined using square brackets
• Lists let you add, remove, or change items — perfect for tasks,
groceries, or any dynamic data.
Example:1
todo_list = ["Math homework", "Science project", "Read Python notes"]
todo_list[0] = "Complete Math homework"
print("Updated To-Do List:", todo_list)
Output:
Updated To-Do List: ['Complete Math homework', 'Science project', 'Read
Python notes']
LIST:
Example : 2
# Creating a list
fruits = ["apple", "banana", "cherry"]
# Accessing elements
print(fruits[1]) # Output: banana
# Modifying an element
fruits[0] = "mango"
print(fruits) # Output: ['mango', 'banana', 'cherry']
# Adding an element
fruits.append("orange")
print(fruits) # Output: ['mango', 'banana', 'cherry', 'orange']
# Removing an element
fruits.remove("banana")
print(fruits) # Output: ['mango', 'cherry', 'orange']
Tuple
A tuple contains an ordered sequence of values. The values can be of
mixed data types and they are separated by commas and are enclosed
with parentheses.
• It is immutable (cannot be changed)
• Ordered collection
• Allows duplicates
• Defined using parentheses ()
• Safer for fixed data.
• Faster than lists due to immutability.
Example:1
# Creating a tuple
colors = ("red", "green", "blue")
# Accessing elements
print(colors[0]) # Output: red
# Length of tuple
print(len(colors)) # Output: 3
Tuple with one element:
Example:
single_tuple = ("apple",) # ← notice the comma!
print(type(single_tuple)) # Output: <class 'tuple'>
Example: 1
# Creating a set
numbers = {1, 2, 3, 4, 5}
print(numbers)
OUTPUT:
# Adding elements
numbers.add(6) {1, 2, 3, 4, 5}
print(numbers) {1, 2, 3, 4, 5, 6}
{1, 2, 4, 5, 6}
# Removing an element {1, 2, 4, 5, 6}
numbers.remove(3)
print(numbers)
print(a.union(b)) # {1, 2, 3, 4, 5}
print(a.intersection(b)) # {3}
print(a.difference(b)) # {1, 2}
# Updating a value
student["grade"] = "9th"
print(student)
# Removing a key
del student["age"]
print(student)
ACTIVITY 2:
x = None
→ What type is this?
t = (1, 2, 3)
→ Can you change the second value?
Question Answer
NoneType – represents
1 absence of value
2 Yes – it's a list, use append()
3 No – it's a tuple (immutable)
ACTIVITY 3: (GROUP)
Code Comparison Challenge Activity
Goal:
• Identify if the data type is mutable or immutable
• Predict the output
# Code 1
colors = ["red", "green", "blue"]
colors[1] = "yellow"
print(colors)
# Code 2
shapes = ("circle", "square", "triangle")
shapes[1] = "rectangle"
print(shapes)
# Code 3
nums = [1, 2, 3]
nums.append(4)
print(nums)
# Code 4
days = ("Mon", "Tue", "Wed")
print(days + ("Thu",))
ACTIVITY 3: - ANSWERS