Oct-04-2019, 04:34 AM
Hi!
This is not a question, but just some musings of mine on Boolean values ... that maybe are useful to some other newbies.
I was learning about Boolean values and their use in conditions, and I didn't know that when used in conditions, 0, 0.0, and "" (the empty string) are considered 'False', while all other values are considered 'True'.
I wanted to check the truth in that (no pun intended!
), so I made this little program:
All the best,
This is not a question, but just some musings of mine on Boolean values ... that maybe are useful to some other newbies.
I was learning about Boolean values and their use in conditions, and I didn't know that when used in conditions, 0, 0.0, and "" (the empty string) are considered 'False', while all other values are considered 'True'.
I wanted to check the truth in that (no pun intended!

name1 = '' name2 = 0 name3 = 0.0 name4 = 6 name5 = 'John' if not name1: print('This means that name1 = "" (empty string) is considered False, \ so not name1 is considered True.') if name1: print('This means that name1 = "" (empty string) is considered True.') if not name2: print('This means that name2 = 0 is considered False, \ so not name2 is considered True.') if name2: print('This means that name2 = 0 is considered True.') if not name3: print('This means that name3 = 0.0 is considered False, \ so not name3 is considered True.') if name3: print('This means that name3 = 0.0 is considered True.') if not name4: print('This means that name4 = 6 is considered False, \ so not name4 is considered True.') if name4: print('This means that name4 = 6 is considered True.') if not name5: print("This means that name5 = 'John' is considered False, \ so not name5 = 'John' is considered True.") if name5: print("This means that name5 = 'John' is considered True.")producing the following self-explanatory output:
Output:This means that name1 = "" (empty string) is considered False, so not name1 is considered True.
This means that name2 = 0 is considered False, so not name2 is considered True.
This means that name3 = 0.0 is considered False, so not name3 is considered True.
This means that name4 = 6 is considered True.
This means that name5 = 'John' is considered True.
>>>
Maybe it's helpful to other newbies.All the best,