Test Series - python

Test Number 20/108

Q: What will be the output of the following Python code?

x = 123
for i in x:
    print(i)
A. 1 2 3
B. 123
C. error
D. none of the mentioned
Solution: Objects of type int are not iterable.
Q: What will be the output of the following Python code?

d = {0, 1, 2}
for x in d.values():
    print(x)
A. 0 1 2
B. a b c
C. error
D. none of the mentioned
Solution: Objects of type set have no attribute values.
Q: What will be the output of the following Python code?

d = {0, 1, 2}
for x in d:
    print(x)
A. 0 1 2
B. {0, 1, 2} {0, 1, 2} {0, 1, 2}
C. error
D. none of the mentioned
Solution: Loops over the elements of the set and prints them.
Q: What will be the output of the following Python code?

d = {0, 1, 2}
for x in d:
    print(d.add(x))
A. 0 1 2
B. 0 1 2 0 1 2 0 1 2 …
C. None None None
D. None of the mentioned
Solution: Variable x takes the values 0, 1 and 2. set.add() returns None which is printed.

You Have Score    /4