Python Tutorials · Python Operators

Assignment Operators

Learn all about Assignment Operators in this comprehensive tutorial.

5 min read beginner
  • Assignment operators are used to assign values to variables:
  • Python 3.

Assignment Operators

Assignment operators are used to assign values to variables:

OperatorExampleSame AsTry it
=x = 5x = 5Try it »
+=x += 3x = x + 3Try it »
-=x -= 3x = x - 3Try it »
*=x *= 3x = x * 3Try it »
/=x /= 3x = x / 3Try it »
%=x %= 3x = x % 3Try it »
//=x //= 3x = x // 3Try it »
**=x **= 3x = x ** 3Try it »
&=x &= 3x = x & 3Try it »
|=x |= 3x = x | 3Try it »
^=x ^= 3x = x ^ 3Try it »
>>=x >>= 3x = x >> 3Try it »
<<=x <<= 3x = x << 3Try it »
:=print(x := 3)x = 3print(x)Try it »

The Walrus Operator

Python 3.8 introduced the := operator, known as the "walrus operator". It assigns values to variables as part of a larger expression:

python

Module quiz

2 questions
1

Which of the following is true about Assignment Operators?

2

What is the most common pitfall when working with Assignment Operators?

Answer all questions to submit.