One-line conditional assignment in Python
Question:
How would you express a one-line conditional assignment in Python?
- x = 1 if y > 10 else 2
- if y > 10: x = 1 else: x = 2
- x = 1 when y > 10 else 2
- x = (y > 10) ? 1 : 2
Answer:
A - is the correct answer