1.5.2

Boolean & Assignment Operators 2

Test yourself

Boolean Operators

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

Illustrative background for AndIllustrative background for And ?? "content

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.
Illustrative background for OrIllustrative background for Or ?? "content

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.
Illustrative background for NotIllustrative background for Not ?? "content

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.

Illustrative background for AssignmentIllustrative background for Assignment ?? "content

Assignment

  • Assignment is done using the = operator. For example:
    • x = 50
Illustrative background for UpdatingIllustrative background for Updating ?? "content

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

Jump to other topics

1Introduction to Python

2Data Structures

2.1Lists & Strings

2.2File Handling

3Modularity

3.1Subroutines

3.2Data Flow

4Good Practice

4.1Naming & Whitespace

4.2Comments

4.3Exceptions

Go student ad image

Unlock your full potential with GoStudent tutoring

  • Affordable 1:1 tutoring from the comfort of your home

  • Tutors are matched to your specific learning needs

  • 30+ school subjects covered

Book a free trial lesson