Page 201 - Information_Practice_Fliipbook_Class11
P. 201
5. [2, 6, 3]*0 will yields ____________.
6. [1, 2].extend([4, 5, 6]) yields ____________.
7. s = []; s.append((1, 2, 3)); print(s) will print ____________.
8. s = []; s.extend((1, 2, 3)); print(s) will print ____________.
9. [1, 2, 3, 4] == [1, 2] + [3, 4] will yield ____________.
10. [1, 2, 3, 4][2:2] will yield ____________.
D. Answer the following questions:
1. What is the difference between mutable and immutable objects? Give an example of an object of each of these types.
Ans. An object that can be modified is called mutable. Example: [1, 2, 3]
An object that cannot be modified is called immutable. Example: (1, 2, 3).
2. Give two examples of mutable types.
Ans. list, and set.
3. Give four examples of immutable types.
Ans. int, float, tuple, str.
4. The function print(x) may be used to display a list (x). Will the output be the same or different in the following case?
Justify your answer. Give the output that will be produced on the execution of the following code.
print([1, 2, 3])
Ans. Elements of a list are separated by commas and enclosed in square brackets [].
[1, 2, 3]
5. Consider the following assignment statement:
lst = list('Term 1 Exam')
Match the following statements with the outputs that will be produced when they are executed.
i. print(lst[1:12:3]) a. []
ii. print(lst[:-8]) b. ['e', ' ', 'E', 'm']
iii. print(lst[-6:0]) c. ['x', 'E', ' ', '1', ' ']
iv. print(lst[-3:-8:-1]) d. ['T', 'e', 'r']
v. print(lst[:24:3]) e. ['T', 'm', ' ', 'a']
Ans. i-b , ii- d, iii- a, iv-c, v-e
6. Give all possible outputs that would print the name of at least one continent when the following code is executed.
import random # Python module to generate random numbers
continents = ['Asia', 'Australia', 'South America', 'North America', 'Europe', 'Antarctica']
lower = random.randint(2, 4) # randint yields random numbers between a given range
upper = random.randint(3, 5)
for x in range(lower, upper):
print(continents[x], end = '#')
Ans. South America#
South America#North America#
South America#North America#Europe#
North America#
North America#Europe#
Europe#
7. Will the following code execute successfully? If yes, what will be the output produced on the execution of the code? If not,
what is the error in the code?
myList = [1, 0, -1]
newList = myList * 3
Python Lists 187

