Boolean & Assignment Operators 2

Coding: Introduction to Python v3, topic 1.5.2

Boolean Operators

Boolean operators perform logical operations and always result in True or False values.

And

And

  • 'and' evaluates to True only if both operands are True.
  • True and True = True.
  • True and False = False.
  • False and True = False.
  • False and False = False.
Or

Or

  • 'or' evaluates to True if any of the two operands are True:
  • True or True = True.
  • True or False = True.
  • False or True = True.
  • False or False = False.
Not

Not

  • 'not' negates a logical value.
  • not True = False.
  • not False = True.

Assignment Operators

Assignment operators allow us to give a variable a value, or to update its value.

Assignment

Assignment

  • Assignment is done using the = operator. For example:
  • x = 50
Updating

Updating

  • We can also use special assignment operators to update the value of a variable, for example:
  • x += 50 is the same as x = x + 50
  • x %= 50 is the same as x = x % 50

Test yourself on Boolean & Assignment Operators 2

  • Which Boolean operator takes only one value as input?

  • What does the following expression in Python return?

    False or True

  • Which of these statements are equivalent to x = x - 5?

  • What is the result of x += 50?

  • Which of the following are valid assignment operators?

Practise this topic for free