Operators

Assignment Operators

🙋 Need help? Ask an expert now!

Re-Assigning values to Variables

Assignment operators are used to assign values to variables:

a = 5 is a simple assignment operator that assigns the value 5 on the right to the variable a on the left. There are various compound operators in Python like a += 5 that adds to the variable and later assigns the same.

Operator Implicit Example Explicit Example English Conversion
= x = 5 x = 5 Set equal to
+= x += 3 x = x + 3 x equals x plus …
-= x -= 3 x = x - 3 x equals x minus …
*= x *= 3 x = x * 3 x equals x times …
/= x /= 3 x = x / 3 x equals x divided …
%= x %= 3 x = x % 3 x equals x modulus …
//= x //= 3 x = x // 3 x equals x integer division …
**= x **= 3 x = x ** 3 x equals x to the power of …

Examples of using this

            
# Declare the variable x x = 5 # Update the variable x += 5 # Print it print(x)