+ 2

How do you know when you have entered a boolean in Python?

Are there any markers, or do you just have to run it and see if it outputs True or False?

11th Mar 2017, 6:16 PM
Ivan
Ivan - avatar
2 Respostas
+ 6
You can convert any expression or variable to a boolean type explicitly with: x = bool(expression_or_variable_name) x will always always be either true or false (or rather True or False :) Besides, if you are using a logical sentence it will do it with its condition anyway (check for its boolean value, whether direct or converted).
11th Mar 2017, 8:21 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 1
there is only a small set of Boolean operators, so it's easy to remember them. additionally, you can always ask yourself the simply question if your expression will evaluate to True (yes) or False (no). With a bit of practice it will come naturally to you!
11th Mar 2017, 7:27 PM
M Z
M Z - avatar