Công Nghệ

Python Tutorial: Boolean Operators In Python #39

See our full tutorial at
Boolean Operators in Python
Couple Python tutorials ago we looked a booleans in this tutorial we are going to take a closer look at Boolean operators in Python. Boolean operators are typically used in conjunction with comparison operators which we looked at in previous tutorials. There are three boolean operators which evaluate if a statement is true or false. The three Boolean operators are “and”, “or” and “not”. Take a look at some key points that we must know before we jump into examples of Boolean operators.

Key points

All objects have a boolean value either True or False.
Empty strings, tuples, list and dictionaries return False.
Non-empty strings, tuples, list and dictionaries return True
Number zero returns False.
Any number other than zero returns True.
Boolean operators stop running as soon as they know the answer which is sometimes referred to as short circuit.
You may want to come back after completing this tutorial to better understand these bulletpoints.

and Boolean Operator
The “and” Boolean will return True if the statement on left and right are True. If one of the statements is False either right or left then Python will return False. Let’s look at a couple examples of the “and” Boolean operator.

Examples of and Boolean Operator

True and True
True and False
False and True

#What happens when we compare numbers? We do not get the simple True or False return rather we get the number on right if both are true or the number on left if number on left if it’s zero. Now we probably will not use this in practice but just proves that each object has a True or False value.
4 and 7
0 and 6

#Same as above with a string. If both are true we get the object on the right and if one on the left False Python will return the left.
“tv” and “xbox”
“” and “xbox”

or Boolean Operator
The “or” Boolean Operator returns True if one of statements is True either right or left. Let’s take a look at some examples.

Example Of “or” Boolean Operator

True or True
True or False
False or True
False or False

not Boolean Operator
The “not” Boolean operator is like opposite day from when you were a kid. When using not if the statement in question is True and Python will return False and if the statement in question is False then Python will return True.

Examples Of “not” Boolean Operator

Do not overthink Boolean operators they are fairly simple. If you have any questions about Boolean operators leave a comment below and we will help you out.


Áo Blazer Nữ Dáng Dài

Previous article

Trực tiếp vòng 38 La Liga: Eibar vs Barcelona

Next article

You may also like


  1. Thank you, your explanation helped me better to understand this.

  2. Man this is a great video thanks man!!! This really helped me you rock!!!!!!

  3. how to use boolean operator in a program ??

  4. Thank you so much great video !!!

  5. Question,
    How do you deal with the statement

    not not True or not not False

  6. Quick and straight to the point. Great video!

  7. True and True is True
    True and False is False
    False and True is False
    False and False is False

    True or True is True
    True or False is True
    False or True is True
    False or False is False

    Not True is False
    Not False is True

  8. what do you hit after last letter of line that the lower line gives you true or false. I hit enter and nothing is hapening?

  9. Thank you! This was very clear.

  10. Thank you for making this video, that helped me to understand booleans better.

  11. Great video.

Leave a reply

Your email address will not be published. Required fields are marked *

More in Công Nghệ