From the course: Python Essential Training

Unlock the full course today

Join today to access over 23,200 courses taught by industry experts.

Booleans

Booleans

- [Instructor] We looked at Booleans earlier, and you might have been left with the impression that there's not a lot left to say about them. True and false, right, how hard could it be? Well, there are a few actually tricky aspects of them that we need to cover. And because I'll use them day in, and day out as a programmer, it's extremely important to cover these. Honestly, I occasionally find myself bringing up a Python terminal to double check a line of boolean logic or confirm exactly how Python handles one case or another. So let's go to the code. The first thing I want to talk about is casting. So Python will cast integers to booleans pretty nicely. 1 is true, and of course 0 is false. In fact, anything except a 0 will be cast a boolean true. So something like -1 might feel false to us, but be careful to Python, it's true. Even something like let's do imaginary one, that's true. However, imaginary zero or float…

Contents