From the course: Python Essential Training
Unlock the full course today
Join today to access over 24,700 courses taught by industry experts.
Booleans - Python Tutorial
From the course: Python Essential Training
Booleans
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. One is true, and of course, zero is false. In fact, anything except a zero will be cast to a Boolean true. So something like negative one 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 0 or float 0 are both false, so 0.0 and if we do 0j, they're false. Okay…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.