How do you define a boolean variable in Python?

There are two ways to define a boolean variable in Python.

Assigning a value directly to a variable.

is_true = True
is_false = False

Use the bool() function to convert other data types to boolean type:

num = 10
is_zero = bool(num)
print(is_zero)  # Output: True

empty_list = []
is_empty = bool(empty_list)
print(is_empty)  # Output: False
bannerAds