Q 1. Suppose list1 is [1, 3, 2], What is list1 * 2?
A. [2, 6, 4]
B. [1, 3, 2, 1, 3]
C. [1, 3, 2, 1, 3, 2]
D. [1, 3, 2, 3, 2, 1]
Show Answer
Answer:-C. [1, 3, 2, 1, 3, 2]Explanation
Execute in the shell and verify.Q 2. Suppose list1 = [0.5 * x for x in range(0, 4)], list1 is:
A. [0, 1, 2, 3]
B. [0.0, 0.5, 1.0, 1.5]
C. [0, 1, 2, 3, 4]
D. [0.0, 0.5, 1.0, 1.5, 2.0]
Show Answer
Answer:-B. [0.0, 0.5, 1.0, 1.5]Explanation
Execute in the shell to verify.Q 3. What will be the output of the following Python code?
- >>>list1 = [11, 2, 23]
- >>>list2 = [11, 2, 2]
- >>>list1 < list2
A. True
B. False
C. Error
D. None
Show Answer
Answer:-B. FalseExplanation
Elements are compared one by one.Q 4. To add a new element to a list we use which command?
A. list1.add(5)
B. list1.addEnd(5)
C. list1.addLast(5)
D. list1.append(5)
Show Answer
Answer:-D. list1.append(5)Explanation
We use the function append to add an element to the list.Q 5. To insert 5 to the third position in list1, we use which command?
A. list1.insert(3, 5)
B. list1.insert(2, 5)
C. list1.add(3, 5)
D. list1.append(3, 5)
Show Answer
Answer:-B. list1.insert(2, 5)Explanation
Execute in the shell to verify.Q 6. To remove string “hello” from list1, we use which command?
A. list1.remove(hello)
B. list1.remove(“hello”)
C. list1.removeAll(“hello”)
D. list1.removeOne(“hello”)
Show Answer
Answer:-B. list1.remove(“hello”)Explanation
Execute in the shell to verify.Q 7. Suppose list1 is [3, 4, 5, 20, 5], what is list1.index(5)?
A. 0
B. 1
C. 4
D. 2
Show Answer
Answer:-D. 2Explanation
Execute help(list.index) to get details.Q 8. Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what is list1.count(5)?
A. 0
B. 4
C. 1
D. 2
Show Answer
Answer:-D. 2Explanation
Execute in the shell to verify.Q 9. What will be the output of the following Python code?
- names1 = [‘Amir’, ‘Bear’, ‘Charlton’, ‘Daman’]
- names2 = names1
- names3 = names1[:]
- names2[0] = ‘Alice’
- names3[1] = ‘Bob’
- sum = 0
- for ls in (names1, names2, names3):
- if ls[0] == ‘Alice’:
- sum += 1
- if ls[1] == ‘Bob’:
- sum += 10
- print sum
A. 11
B. 12
C. 21
D. 22
Show Answer
Answer:-B. 12Explanation
When assigning names1 to names2, we create a second reference to the same list. Changes to names2 affect names1. When assigning the slice of all elements in names1 to names3, we are creating a full copy of names1 which can be modified independently.Q 10. What will be the output of the following Python code?
- >>>names = [‘Amir’, ‘Bear’, ‘Charlton’, ‘Daman’]
- >>>print(names[-1][-1])
A. A
B. Daman
C. Error
D. n
Leave a Reply