ProgrammingHardTCS NQT · Wipro pattern
What is printed?
What is printed?
print(str(()), str([()]), repr(('a',)), str(('a', 1)))- A. () () ('b') ('a', 1)
- B. () [()] ('a',) ('a', 1)
- C. () [()] ('c') ('a', 1)
- D. () [] ('a',) ('a', 2)
Correct answer: B. () [()] ('a',) ('a', 1)
str of an empty tuple is (), and a list containing it prints as [()]. A one-element tuple keeps its trailing comma in repr, and the two-element tuple shows both values.
More Python Programming questions
- What is printed? python x = 10 def f(): return x x = 20 print(f(), (lambda y=x: y)(), [lambda: i for i in range(2)][1]())
- What is printed? python print(list(map(int, '1 2 3'.split())), list(map(str.upper, 'ab')), sum(map(int, '9' 3)) % 7)
- What is printed? python print('%.3g' % 0.0001234, '%.3g' % 123456.0, '%g' % 1e-5, '%G' % 1e-10)
- What is printed? python print(max([1, 2], [1, 2, 0]) == [1, 2, 0], min((1, 'a'), (1, 'b')), sorted([(1, 'b'), (1, 'a')])[0][1])
- What is printed? python print(3 [0] == [0, 0, 0], [0] 3 is [0] 3, 'a' in 'abc' in 'abcdef')
- What is printed? python print(sum([1, 2, 3]) / 2 // 1, 7 // 2 / 2, divmod(7.0, 2)[0] == 7 // 2)