Page 229 - Information_Practice_Fliipbook_Class11
P. 229
3
5
7
9
4. What will be the output of the following code segment?
a. myList = [1,2,3,4,5,6,7,8,9,10]
del myList[3:]
print(myList)
b. myList = [1,2,3,4,5,6,7,8,9,10]
del myList[:5]
print(myList)
c. myList = [1,2,3,4,5,6,7,8,9,10]
del myList[::2]
print(myList)
Ans. a. [1, 2, 3]
b. [6, 7, 8, 9, 10]
c. [2, 4, 6, 8, 10]
5. Differentiate between append() and extend() methods of list.
Ans. Refer to 7.7 List Methods
6. Consider a list:
list1 = [6,7,8,9]
What is the difference between the following operations on list1:
a. lis t1 * 2
b. lis t1 *= 2
c. lis t1 = lis t1 * 2
Ans. a. list1 * 2: This operation creates a new list by repeating the elements of list1 twice. The original list remains unchanged.
b. list1 *= 2: This operation modifies the original list by repeating its elements twice in place. New list1 is
[6, 7, 8, 9, 6, 7, 8, 9]
c. This operation creates a new list by repeating the elements of list1 twice and then assigns this new list to list1, replacing the original
list. Output is: [6, 7, 8, 9, 6, 7, 8, 9]
7. The record of a student (Name, Roll No, Marks in five subjects and percentage of marks) is stored in the following list:
stRecord = ['Raman','A-36',[56,98,99,72,69], 78.8]
Write Python statements to retrieve the following information from the list stRecord.
a. Percentage of the student
b. Marks in the fifth subject
c. Maximum marks of the student
d. Roll No. of the student
e. Change the name of the student from ‘Raman’ to ‘Raghav’
Ans. a. print("Percentage of the student : ", stRecord[3])
b. print("Marks in the fifth subject : ", stRecord[2][4])
c. print("Maximum marks of the student :", max(stRecord[2]))
d. print("Roll no. of the student :", stRecord[1])
e. stRecord[0] = "Raghav"
8. Consider the following dictionary stateCapital:
stateCapital = {"Assam":"Guwahati", "Bihar":"Patna","Maharashtra":"Mumbai", "Rajasthan":"Jaipur"}
Find the output of the following statements:
a. print(stateCapital.get("Bihar"))
b. print(stateCapital.keys())
c. print(stateCapital.values())
d. print(stateCapital.items())
Python Dictionaries 215

