Python Fundamentals: Booleans
Python Booleans are one of Python's built-in data types. They are used to represent truth values (True or False).
a. Creating a boolean: Booleans in Python can be created by assigning True or False to a variable.
bool1 = True
bool2 = False
b. Boolean operations: Python includes the following boolean operations - and, or, not.
print(True and False)
print(True or False)
c. Boolean in conditional statements: Booleans are often used in conditional statements to decide which action Python should execute.
x = 10
if x > 5:
print('x is greater than 5')
print('x is not greater than 5')
Copyright © 2023 - slash-root.com