1.2 KiB
1.2 KiB
title | tags | aliases | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
booleans |
|
|
[!note] Concept Python uses the
bool
type to represent truth values. It has only two values:True
andFalse
, both of which are subtypes ofint
.[!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
andFalse
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
- logicalOperators — details
and
,or
,not
in more depth- conditionals — where booleans are used for flow control
- typeConversions — shows how other types convert to
bool
- numericTypes — relevant because
bool
is a subtype ofint