0% found this document useful (0 votes)
19 views4 pages

Understanding Python Booleans

In Python, expressions can be evaluated to return Boolean values, either True or False. Most values are considered True unless they are empty or equal to zero, while specific values like None and False evaluate to False. The document provides examples of evaluating different data types to illustrate these concepts.

Uploaded by

abhishekabix08
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views4 pages

Understanding Python Booleans

In Python, expressions can be evaluated to return Boolean values, either True or False. Most values are considered True unless they are empty or equal to zero, while specific values like None and False evaluate to False. The document provides examples of evaluating different data types to illustrate these concepts.

Uploaded by

abhishekabix08
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

Booleans datatype

• You can evaluate any expression in Python, and get one of two answers, True
or False.

• When you compare two values, the expression is evaluated and Python
returns the Boolean answer:
• print(10 > 9)
print(10 == 9)
print(10 < 9)
• Try it Yourself »
Evaluate Values and Variables

• print(bool("Hello"))
print(bool(15))

• Try it Yourself »
• x = "Hello"
y = 15

print(bool(x))
print(bool(y))
• Almost any value is evaluated to True if it has some sort of content.

• Any string is True, except empty strings.

• Any number is True, except 0.

• Any list, tuple, set, and dictionary are True, except empty ones.
• there are not many values that evaluate to False, such as (), [], {}, "", the
number 0, and the value None. And of course the value False evaluates to
False.
• bool("abc")
• bool(123)
• bool(["apple", "cherry", "banana"])
• bool(False)
bool(None)
bool(0)
bool("")
bool(())
bool([])
bool({})

You might also like