Data Structures & AlgorithmsHardTCS NQT Digital · Python semantics
Problem: What does the following print?
Problem: What does the following print?
a = (1,) print(a * 3, len(a * 0))What is printed?
- A. (1, 1, 1) 1
- B. (1,) 0
- C. (1, 1, 1) 3
- D. (1, 1, 1) 0
Correct answer: D. (1, 1, 1) 0
Tuple multiplication repeats the tuple, so a * 3 is (1, 1, 1); multiplying by 0 gives the empty tuple of length 0.
More Coding Interview Problems questions
- Problem: What does the following print? python print(list('abc')[::-1] == ['c', 'b', 'a'], 'abc'.index('c')) What is printed?
- Problem: What does the following print? python x = 5 x <<= 2 x |= 1 print(x) What is printed?
- Problem: What does the following print? python print(any([]), all([])) What is printed?
- Problem: What does the following print? python print(10 20 // 10 18) What is printed?
- Problem: What does the following print? python print(float('inf') > 10 100, -0.0 == 0.0) What is printed?
- Problem: What is the 1-indexed survivor when n = 6 people stand in a circle and every 3rd person is removed? Run the recurrence code…