Assignment Operators in Python
-
Assignment operators in Python are used to assign values to variables. They not only store data but can also perform operations while assigning, making code shorter and easier to read.
Assignment Operators
Assignment operators in Python are used to store values in variables and can also perform an operation and assign the result to the same variable in a shorter way.
Assignment operators make code shorter, cleaner, and easier to read.
Assignment Operators Example
Demonstrates the use of different assignment operators in Python.
# Python program to demonstrate assignment operators
a = 10 # Assign value
print("Initial value of a:", a)
a += 5 # a = a + 5
print("After a += 5:", a)
a -= 3 # a = a - 3
print("After a -= 3:", a)
a *= 2 # a = a * 2
print("After a *= 2:", a)
a /= 4 # a = a / 4
print("After a /= 4:", a)
a %= 3 # a = a % 3
print("After a %= 3:", a)
a **= 2 # a = a ** 2
print("After a **= 2:", a)
a //= 2 # a = a // 2
print("After a //= 2:", a)