Main.BooleanVariables History

Hide minor edits - Show changes to markup

January 31, 2013, at 03:30 PM MST by 129.82.44.223 -
Changed line 22 from:
  1. done't confuse the comparison operator == with the assignment operator =
to:
  1. don't confuse the comparison operator == with the assignment operator =
January 28, 2010, at 03:02 PM MST by 129.82.44.241 -
Added lines 1-53:

(:source lang=python:)

"""Boolean values and expressions"""

  1. a Boolean variable has one of two values: True or False

type(True)

  1. when we assign a Boolean value to a variable it becomes
  2. a Boolean variable

a = False type(a)

  1. A boolean expression is an expression that evaluates to a boolean value.
  2. The operator == compares two values and produces a boolean value:

5 == 5 5 == 6

  1. done't confuse the comparison operator == with the assignment operator =
  2. 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

  1. logical operators: and, or, not

x = 2 x > 0 and x < 10

  1. True if x is greater than 0 and less than 10

x % 2 == 0 or x % 3 == 0

  1. True if either of the conditions is true, that is,
  2. if the number is divisible by 2 or 3
  3. not is the negation operator:

not(True) not(False) x = 1 y = 2 not(x > y)

(:sourceend:)