Welcome to the lesson on Python Booleans
Booleans represent one of two values: True or False.
Boolean Values
In programming you often need to know if an expression is True or False.
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:
Example:
Python returns True or False, when we run a condition in an if statement.
Some Examples: Print a message based on whether the condition is True or False:
Evaluate Values and Variables
The bool() function allows you to evaluate any value, and give you True or False in return,
Some Examples: Evaluate a string and a number:
Some Examples: Evaluate two variables:
Functions can Return a Boolean
You can create functions that returns a Boolean Value:
Some Examples: Print the answer of a function:
You can execute code based on the Boolean answer of a function:
Some Examples: Print "YES!" if the function returns True, otherwise print "NO!"::
End of Python Booleans
You have learned Booleans in simple terms. Let's proceed on to Quiz.