Test Series - python

Test Number 37/108

Q: 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]
Solution: Execute in the shell and verify.
Q: Suppose list1 = [0.5 * x for x in range(0, 4)], list1 is:
A. [0, 1, 2, 3]
B. [0, 1, 2, 3, 4]
C. [0.0, 0.5, 1.0, 1.5]
D. [0.0, 0.5, 1.0, 1.5, 2.0]
Solution: Execute in the shell to verify.
Q:  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
Solution: Elements are compared one by one.
Q: To add a new element to a list we use which command?
A. list1.add(5)
B. list1.append(5)
C. list1.addLast(5)
D. list1.addEnd(5)
Solution: We use the function append to add an element to the list.
Q: 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)
Solution: Execute in the shell to verify.
Q: 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”)
Solution: Execute in the shell to verify.
Q: Suppose list1 is [3, 4, 5, 20, 5], what is list1.index(5)?
A. 0
B. 1
C. 4
D. 2
Solution: Execute help(list.index) to get details.
Q: Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what is list1.count(5)?
A. 0
B. 4
C. 1
D. 2
Solution: Execute in the shell to verify.

You Have Score    /8