ProgrammingVery hardTCS NQT · Accenture
What is printed?
What is printed?
x = [1, 2, 3] print(x.pop(), x.pop(0), x, x.insert(0, 9) or x)
- A. 3 1 [9, 2] [9, 2]
- B. 3 1 [2] [9, 2]
- C. 3 1 [2] [2]
- D. 3 1 [9, 2] [2]
Correct answer: A. 3 1 [9, 2] [9, 2]
Print evaluates all its arguments before printing. pop removes 3 and then 1, the list becomes [2], and then insert puts 9 in front. Both references to x show the final list.
More Python Programming questions
- What is printed? python print(max(map(len, ['a', 'bbb', 'cc'])), min(len(s) for s in ['a', 'bbb']), sum(len(s) for s in ['ab', 'c']))
- What is printed? python print(float('1e2') == 100, int(float('1e2')), str(float('1e2')), int('100'))
- What is printed? python print(round(1.0000000000000002, 15) == 1, 1.0000000000000002 == 1, 1.0000000000000002 - 1 == 2.220446049250313e-16)
- What is printed? python s = 'hello world' print(s.title().split()[1][::-1], s.rsplit(' ', 1)[0], s.count('o', 5))
- What is printed? python print(int(0.1 10), round(0.1 10, 10) == 1, 0.1 10 == 1)
- What is printed? python print(abs(-0.0), abs(-3), abs(True), abs(-2 63))