I am Python newbie, so maybe don't knew if this is obvious or not.
In Javascript a||b
returns a
if a
is evaluated to true, else returns b
.
Is that possible in Python other than lengthy if else statement.
I believe this is correct:
x = a or b
This is how "||
" works in JavaScript:
> 'test' || 'again'
"test"
> false || 'again'
"again"
> false || 0
0
> 1 || 0
1
This is how "or
" works in Python:
>>> 'test' or 'again'
'test'
>>> False or 'again'
'again'
>>> False or 0
0
>>> 1 or 0
1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With