Data Structures & AlgorithmsModerateTCS NQT Digital · Python semantics
Problem: What does the following print?
Problem: What does the following print?
a = [1, 2, 3] b = a b += [4] print(a)
- A. [1, 2, 3]
- B. [4]
- C. [1, 2, 3, 4]
- D. Error
Correct answer: C. [1, 2, 3, 4]
The += operator on a list extends it in place, so a and b remain the same object and a sees the new element.
More Coding Interview Problems questions
- Problem: What does the following print? python print(int('0b101', 0), int('101', 2), 7 // 2 2)
- Problem: What does the following print? python fs = [lambda: i for i in range(3)] print([f() for f in fs])
- Problem: What does the following print? python print(len({1, 2, 3} & {2, 3, 4} | {5}))
- Problem: What does the following print? python print('10' < '9', 10 < 9)
- Problem: What does the following print? python print(int('12', 8) + int('0x1f', 16))
- Problem: How many strings of length 4 over {a, b} contain neither 'aa' nor 'bb' as a substring? Run the code. python from itertools import…