Python Developer Question:
Download Job Interview Questions and Answers PDF
Tell me how Does The Ternary Operator Work In Python?
Answer:
The ternary operator is an alternative for the conditional statements. It combines of the true or false values with a statement that you need to test. The syntax would look like the one given below.
[onTrue] if [Condition] else [onFalse]
x, y = 35, 75
smaller = x if x < y else y
print(smaller)
[onTrue] if [Condition] else [onFalse]
x, y = 35, 75
smaller = x if x < y else y
print(smaller)
Download Python Developer Interview Questions And Answers
PDF
Previous Question | Next Question |
Do you know what Is The Key Difference Between A List And The Tuple? | Do you know what Does The <Yield> Keyword Do In Python? |