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.

Using the Python and Operator (Overview)

Python has three Boolean operators, or logical operators: and, or, and not. You can use them to check if certain conditions are met before deciding the execution path your programs will follow. In this video course, you’ll learn about the and operator and how to use it in your code.

In this video course, you’ll learn how to:

  • Understand the logic behind Python’s and operator
  • Build and understand Boolean and non-Boolean expressions that use the and operator
  • Use the and operator in Boolean contexts to decide the course of action of your programs
  • Use the and operator in non-Boolean contexts to make your code more concise

You’ll also code a few practical examples that will help you understand how to use the and operator to approach different problems in a Pythonic way. Even if you don’t use all the features of and, learning about them will allow you to write better and more accurate code.

Download

Sample Code (.zip)

3.8 MB

Download

Course Slides (.pdf)

1.2 MB

00:00 Hello, and welcome to this course on Using the Python and Operator. If you’re familiar with conditionals for things like if statements and while loops and you’re ready to create more refined conditions, then you will find this course very useful.

00:16 In this course, we’ll look at the basics of the and operator, show how it can be used in conditionals, and then take a look at some of the unique ways it can be used in Python for more interesting programming techniques.

00:29 and as one of the three Boolean operators implemented in Python. The other two are called or and not. Boolean expressions are used in conditionals to control the flow of instructions in a Python program.

00:44 This course is specifically about the and operator, and it’s based on a similar tutorial by Leodanis Pozo Ramos. You can find more tutorials and courses on Boolean operators here at Real Python. After completing this course, you will know how the Python and operator works, how to use the and operator in both Boolean and non-Boolean contexts, what types of programs you can write using the and operator, and how to better understand other programmers’ code when they use the and operator in interesting ways.

01:22 Let me tell you about the tools I’ll be using in this course. For Python program files, I use Visual Studio Code with a Dark+ theme. My terminal shell is iTerm2 from macOS. And for my REPL, I use ptpython with its native theme. I’m Howard Francis, and I’m excited to lead you through this course on the Python and operator.

01:47 So let’s get started.

Become a Member to join the conversation.