Page 451 - ComputerScience_Class_11
P. 451
8. What is the difference between a list and a tuple in Python?
Ans. Here are the differences between List and Tuple in Python:
Features List [ ] Tuple ( )
Definition A sequence data type that is mutable A sequence data type that is immutable
Mutability Elements can be changed, added or removed Elements cannot be changed after creation
Syntax Uses square brackets [ ] Uses parentheses ( )
Speed Slower compared to tuple Faster than list
Memory Usage Uses more memory Uses less memory
Usage Used when data needs modification Used for fixed or read-only data
Example a = [1, 2, 3] b = (1, 2, 3)
D. Higher Order Thinking Skills (HOTS)
1. A library wants to store book details (ID, title, author, price). Why is a dictionary suitable for this and show a Python example for
three books?
Ans. A dictionary is suitable because each book has a unique ID that can be used as a key to quickly access its details.
Example:
books = {
"B101": {"title": "Python Basics", "author": "Riya", "price": 500},
"B102": {"title": "Data Science", "author": "Rahul", "price": 750},
"B103": {"title": "AI Fundamentals", "author": "Ankit", "price": 600}
}
print(books)
2. A student wants to store the full names of all classmates in a Python program. Explain why a sequence of characters enclosed in
quotes is suitable for this task. How does immutability affect modify the names directly?
Ans. A sequence of characters in quotes is suitable for storing full names because it can hold letters, spaces and symbols in one
variable, with each character having a fixed position for easy access. Being immutable, the names cannot be changed directly; a
new value must be created to modify them.
E. Assertion and reasoning questions.
The following questions consist of two statements – Assertion (A) and Reason (R). Answer these questions by selecting the
appropriate option given below:
a. Both A and R are true and R is the correct explanation of A.
b. Both A and R are true but R is not the correct explanation of A.
c. A is true but R is false.
d. A is false but R is true.
1. A complex number in Python is written in the form a + bj, where a is the real part, b is the imaginary part and j represents √-1.
Reason (R): Complex numbers are used in advanced mathematical, scientific, engineering and graphical computations.
Ans. a. Both A and R are true and R is the correct explanation of A.
2. Assertion (A): None in Python represents the absence of a value and belongs to the NoneType data type.
Reason (R): None is the same as 0, False or an empty string "" in Python.
Ans. c. A is true but R is false.
3. Assertion (A): A mixed list in Python can store elements of different data types in a single list.
Reason (R): All elements in a mixed list must be of the same data type.
Ans. c. A is true but R is false.
Data Types in Python 449

