Test Series - python

Test Number 75/108

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

x = [12, 34]
print(len(list(map(len, x))))
A. 2
B. 1
C. error
D. none of the mentioned
Solution: TypeError, int has no len().
Q: What will be the output of the following Python code?

x = [12, 34]
print(len(list(map(int, x))))
A. 2
B. 
C. error
D. 
Solution: list(map()) returns a list of two items in this example.
Q: What will be the output of the following Python code?

x = [12, 34]
print(len('.join(list(map(int, x)))))
A. 
B. 
C. error
D. 
Solution: Cannot perform join on a list of ints.
Q: What will be the output of the following Python code?

x = [12, 34]
print(len('.join(list(map(str, x)))))
A. 4
B. 5
C. error
D. 
Solution: Each number is mapped into a string of length 2.
Q: What will be the output of the following Python code?

x = [12, 34]
print(len(.join(list(map(int, x)))))
A. 6
B. 8
C. error
D. 
Solution: TypeError. Execute in shell to verify.
Q: What will be the output of the following Python code?

x = [12.1, 34.0]
print(len(.join(list(map(str, x)))))
A. 6
B. 7
C. error
D. 9
Solution: The floating point numbers are converted to strings and joined with a space between them.
Q: What will be the output of the following Python code?

x = [12.1, 34.0]
print(.join(list(map(str, x))))
A. 12 1 34 0
B. 12.1 34
C. error
D. 12.1 34.0
Solution: str(ab.c) is ‘ab.c’.
Q: What will be the output of the following Python code?

x = [[0], [1]]
print(len(.join(list(map(str, x)))))
A. 2
B. 3
C. error
D. 7
Solution: map() is applied to the elements of the outer loop.

You Have Score    /8