0 votes
in Python Flask by
Explain the ternary operator in Python.

1 Answer

0 votes
by
Unlike C++, we don’t have ?: in Python, but we have this:

[on true] if [expression] else [on false]

If the expression is True, the statement under [on true] is executed. Else, that under [on false] is executed.

Below is how you would use it:
AD

>>> a,b=2,3
>>> min=a if a<b else b
>>> min
2

>>> print("Hi") if a<b else print("Bye")
Hi

Related questions

0 votes
asked Oct 9, 2022 in JavaScript by Robin
0 votes
asked Oct 5, 2021 in Kotlin by rajeshsharma
...