Main.BooleanVariables History
Hide minor edits - Show changes to markup
January 31, 2013, at 03:30 PM MST
by -
Changed line 22 from:
- done't confuse the comparison operator == with the assignment operator =
to:
- don't confuse the comparison operator == with the assignment operator =
January 28, 2010, at 03:02 PM MST
by -
Added lines 1-53:
(:source lang=python:)
"""Boolean values and expressions"""
- a Boolean variable has one of two values: True or False
type(True)
- when we assign a Boolean value to a variable it becomes
- a Boolean variable
a = False type(a)
- A boolean expression is an expression that evaluates to a boolean value.
- The operator == compares two values and produces a boolean value:
5 == 5 5 == 6
- done't confuse the comparison operator == with the assignment operator =
- other comparison operators
x = 1 y = 2
x != y # x is not equal to y x > y # x is greater than y x < y # x is less than y x >= y # x is greater than or equal to y x <= y # x is less than or equal to y
- logical operators: and, or, not
x = 2 x > 0 and x < 10
- True if x is greater than 0 and less than 10
x % 2 == 0 or x % 3 == 0
- True if either of the conditions is true, that is,
- if the number is divisible by 2 or 3
- not is the negation operator:
not(True) not(False) x = 1 y = 2 not(x > y)
(:sourceend:)
