0% found this document useful (0 votes)
2 views2 pages

Grade IX Python Variables

The document outlines various Python data types including numeric types (int, float, complex), sequence types (str, list, tuple), mapping type (dict), set types (set, frozenset), boolean type (bool), and binary types (bytes, bytearray). Each type is accompanied by examples and practice exercises for students to apply their knowledge. The content is designed for Class IX students at Dr. Dasarathan International School, Coimbatore.

Uploaded by

vinodhini
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Grade IX Python Variables

The document outlines various Python data types including numeric types (int, float, complex), sequence types (str, list, tuple), mapping type (dict), set types (set, frozenset), boolean type (bool), and binary types (bytes, bytearray). Each type is accompanied by examples and practice exercises for students to apply their knowledge. The content is designed for Class IX students at Dr. Dasarathan International School, Coimbatore.

Uploaded by

vinodhini
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Dr.

DASARATHAN INTERNATIONAL SCHOOL, COIMBATORE -17


(Affiliated to the Council for the Indian School Certificate Examinations, New Delhi)

Class: IX Python data types


1. Numeric Types
int, float, complex
# Examples
a = 10 # int
b = 3.14 # float
c = 2 + 3j # complex

print(type(a)) # <class 'int'>


print(type(b)) # <class 'float'>
print(type(c)) # <class 'complex'>
💡 Try this:
x=5
y = 2.5
z = 1 + 2j

print("Sum:", x + y)
print("Real part of z:", z.real)
print("Imaginary part of z:", z.imag)

✅ 2. Sequence Types
▶ str
name = "Python"
print(name.upper()) # Output: PYTHON
print(name[0]) # Output: P
▶ list
fruits = ["apple", "banana", "cherry"]
fruits.append("mango")
print(fruits) # ['apple', 'banana', 'cherry', 'mango']
▶ tuple
colors = ("red", "green", "blue")
print(colors[1]) # green
💡 Try this:
names = ["John", "Jane", "Doe"]
names[1] = "Janet"
print("Updated list:", names)

✅ 3. Mapping Type – dict


student = {"name": "Alice", "age": 15}
print(student["name"]) # Output: Alice

# Adding a new key


student["grade"] = "10th"
print(student)
💡 Try this:
person = {"name": "Bob", "city": "Delhi"}
print("City:", person.get("city"))

✅ 4. Set Types
▶ set
nums = {1, 2, 3, 2, 1}
print(nums) # Output: {1, 2, 3} (no duplicates)
▶ frozenset
frozen = frozenset([1, 2, 3])
print(frozen)
💡 Try this:
a = {1, 2, 3}
b = {3, 4, 5}
print("Union:", a | b)
print("Intersection:", a & b)

✅ 5. Boolean Type – bool


x = 10
y=0

print(bool(x)) # True
print(bool(y)) # False
💡 Try this:
a=5
b=7
print("Is a < b?", a < b)

✅ 6. Binary Types
▶ bytes, bytearray, memoryview
b = bytes("hello", "utf-8")
print(b) # b'hello'

ba = bytearray(b)
ba[0] = 72 # 'h' → 'H'
print(ba) # bytearray(b'Hello')

✅ Practice Set
📝 Questions:
1. Create a list of 3 of your favorite movies.
2. Convert your name into uppercase using a string method.
3. Create a dictionary with your name, age, and city.
4. Create a set with some duplicate numbers and print it.
5. Print whether 25 is greater than 50 using Boolean.

You might also like