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.
Code
bool1 = True
bool2 = False
print(bool1)
print(bool2)
Output
b. Boolean operations: Python includes the following boolean operations - and, or, not.
Code
print(True and False)
print(True or False)
print(not True)
Output
c. Boolean in conditional statements: Booleans are often used in conditional statements to decide which action Python should execute.
Code
x = 10
if x > 5:
print('x is greater than 5')
else:
print('x is not greater than 5')
Output
Enquiries
[email protected]
Copyright © 2023 - slash-root.com