ProgrammingHardTCS NQT · Accenture
What is printed?
What is printed?
print(1 if 0 else 2 if 1 else 3, (lambda: 1 if False else 'x')())
- A. 1 x
- B. 3 x
- C. 2 x
- D. 2 1
Correct answer: C. 2 x
Conditional expressions nest to the right, so 0 is false and the second branch gives 2. The lambda's inner conditional is false and returns 'x'.
More Python Programming questions
- What is printed? python print(type(1/1).name, type(1//1).name, type(2-1).name, type(21).name)
- What is printed? python print(sorted({x % 4 for x in range(10)}))
- What is printed? python print('xxhixx'.strip('x') + '|' + 'abc'.strip('ac'))
- What is printed? python print(len(str(2100)), str(2100)[:5])
- What is printed? python print(sorted([[2, 'b'], [1, 'z'], [2, 'a']]))
- What is printed? python x = [1, 2, 3] y = x.copy() y.append(4) print(len(x), len(y), x is y)