Python ternary operator introduced in Python 2.5.
[on_true] if [expression] else [on_false]
x, y = 50, 25
small = x if x < y else y
Before this syntax was introduced in Python 2.5, a common idiom was to use logical operators:
[expression] and [on_true] or [on_false]
However, this idiom is unsafe, as it can give wrong results when on_true has a false boolean value. Therefore, it is always better to use the ... if ... else ... form.
source : https://docs.python.org/3.3/faq/programming.html#is-there-an-equivalent-of-c-s-ternary-operator
Apache (5)
CSS (3)
Docker (6)
Git (5)
Go (1)
Hobbies & Toys (8)
HTML (4)
Javascript (5)
jQuery (3)
Linux Ubuntu (46)
Misc (36)
MySQL (3)
Odoo (13)
PHP (3)
Pipeline (1)
Postgresql (6)
Python (13)
Quote (1)
Qweb (1)
Random Word (1)
Smartphone (1)
SQL Server (1)
Tools (7)
Useful Links (46)
Video (3)
VLC (1)
Vue (1)
Web Server (3)
zuka.one
©2011