python to boolean code example

Example 1: convert string to boolean python

def str2bool(v):

   return str(v).lower() in ("yes", "true", "t", "1")

Example 2: boolean python

# Booleans represent one of two values: True or False.
# When you compare two values, the expression is evaluated and Python returns the Boolean answer:
print(10 > 9)
> True
print(10 < 9)
> False
# All True Examples
bool("abc")
bool(123)
bool(["apple", "cherry", "banana"])
# All False Examples
bool(False)
bool(None)
bool(0)
bool("")
bool(())
bool([])
bool({})