Boolean Expressions

Boolean Values & Expressions

bool1 = True
  • A Boolean value directly assigned as True.

bool2 = 3*3 == 9
  • Evaluates if 3 * 3 is equal to 9True.

bool3 = False
  • A Boolean value directly assigned as False.

bool4 = 3*3 != 9
  • Evaluates if 3 * 3 is not equal to 9False.


Output:

print(bool1, bool2, bool3, bool4)
  • Displays the values:

    True True False False
print(type(bool1))
  • Shows the data type of bool1, which is:

    <class 'bool'>

Summary:

  • Boolean values: True or False.

  • Used in comparisons like == (equals) and != (not equals).

  • Helpful in conditions and decision-making in code.

#!/bin/python3

#Boolean Expressions
bool1 = True
bool2 = 3*3 == 9
bool3 = False
bool4 = 3*3 != 9
print(bool1,bool2,bool3,bool4)
print(type(bool1))

Last updated