voidex/20-29 Areas/20 Programming/20.01 Python/booleans.md

1.2 KiB

title tags aliases
booleans
python
bool
logic
expressions
true
false
boolean
bools

[!note] Concept Python uses the bool type to represent truth values. It has only two values: True and False, both of which are subtypes of int.

[!example] Assigning Boolean Values

true_variable = True
false_variable = False

[!example] Boolean Expressions

result = True and True      # True
result = True and False     # False
result = False or True      # True
result = False or False     # False
result = not False          # True
result = not True           # False

[!important] Best Practices

  • True and False must be capitalized.
  • Use boolean logic to control flow and conditionals.
  • Booleans are a subtype of int:
    int(True)   # 1
    int(False)  # 0
    

[!info]- 🔗 Related Notes