The Python Oracle

Python shorthand conditional

--------------------------------------------------
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
and get $2,000 discount on your first invoice
--------------------------------------------------

Take control of your privacy with Proton's trusted, Swiss-based, secure services.
Choose what you need and safeguard your digital life:
Mail: https://go.getproton.me/SH1CU
VPN: https://go.getproton.me/SH1DI
Password Manager: https://go.getproton.me/SH1DJ
Drive: https://go.getproton.me/SH1CT


Music by Eric Matyas
https://www.soundimage.org
Track title: Puzzle Game 2

--

Chapters
00:00 Python Shorthand Conditional
00:24 Accepted Answer Score 33
00:31 Answer 2 Score 1
01:00 Thank you

--

Full question
https://stackoverflow.com/questions/6608...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#python #ifstatement #conditional

#avk47



ACCEPTED ANSWER

Score 33


Call bool on the object:

bool(bar1)



ANSWER 2

Score 1


Similar to JavaScript, you can use logical negation in Python. This uses the keyword not. One disadvantage of bool is you can change its value, as this is not a reserved word. If bool variable's value is not callable. For example, bool = 7, an error will be raised. If bool variable's value is callable. For example, bool = int, you may get an unexpected value.

JavaScript

!!bar1

Python

not not bar1