Join us and get access to hundreds of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to hundreds of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set the default subtitles language in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please see our video player troubleshooting guide to resolve the issue.

Python Booleans: Leveraging the Values of Truth (Summary)

The Python Boolean is a commonly used data type with many useful applications. You can use Booleans with operators like not, and, or, in, is, ==, and != to compare values and check for membership, identity, or equality. You can also use Boolean testing with an if statement to control the flow of your programs based on the truthiness of an expression.

You now know how short-circuit evaluation works and recognize the connection between Booleans and the if statement. This knowledge will help you to both understand existing code and avoid common pitfalls that can lead to errors in your own programs.

In this course, you’ve learned how to:

  • Manipulate Boolean values with Boolean operators
  • Convert Booleans to other types
  • Convert other types to Python Booleans
  • Use Booleans to write efficient and readable Python code

Download

Sample Code (.zip)

4.9 KB

Download

Course Slides (.pdf)

1.6 MB

Alain Rouleau on March 16, 2021

Thanks for the course. Good coverage of the big picture along with all the various intricacies. Not always easy to figure things out when it comes to Booleans.

Andrew on March 17, 2021

A succinct and descriptive coverage. Many thanks!!!

markengle on June 28, 2021

I really enjoyed the coverage of chaining comparison and membership operators! Thanks for the lesson.

Become a Member to join the conversation.