0% found this document useful (0 votes)
7 views7 pages

Data Types - Boolean

The document explains Booleans, which can represent either True or False values. It details how to evaluate values using the bool() function and lists conditions under which various data types are considered True or False. Additionally, it provides example functions demonstrating the use of Boolean evaluations in Python.
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)
7 views7 pages

Data Types - Boolean

The document explains Booleans, which can represent either True or False values. It details how to evaluate values using the bool() function and lists conditions under which various data types are considered True or False. Additionally, it provides example functions demonstrating the use of Boolean evaluations in Python.
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

Agenda

• Booleans
Booleans

Booleans represent one of two


values: True or False.
When you compare two values
• print(10 > 9)
• print(10 == 9)
• print(10 < 9)
Evaluate Values

print(bool("Hello"))
print(bool(15))
When the values are True
• Any string is True, except empty strings.
• Any number is True, except 0.
• Any list, tuple, set, and dictionary are True,
except empty ones.
bool("abc")
bool(123)
bool(["apple", "cherry", "banana"])
When the values are False
• print(bool(None))
• print(bool(0))
• print(bool(""))
• print(bool([]))
• print(bool({}))
Class Example
# This is for the boolean datatype
def boolean_true():
print(123 > 45)
print(321 > 54)
print(bool(1234))
print(bool("123456"))
print(bool({123456: 654321}))
print(bool([1, "Shayaan", "Apple"]))

def boolean_false():
print(bool())
print(bool(""))
print(bool({}))
print(bool([]))
print(bool(0))
print(bool(None))

boolean_true()

boolean_false()

You might also like