0% found this document useful (0 votes)
8 views2 pages

Assignment Operators

Assignment operators in Python are used to assign values to variables and can combine assignment with arithmetic operations. The document outlines various types of assignment operators, including simple assignment (=) and compound assignment operators like +=, -=, and others, along with examples for each. A summary table is also provided to illustrate the results of different assignment operations when starting with a variable value of 10.

Uploaded by

kalpanapriyam213
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views2 pages

Assignment Operators

Assignment operators in Python are used to assign values to variables and can combine assignment with arithmetic operations. The document outlines various types of assignment operators, including simple assignment (=) and compound assignment operators like +=, -=, and others, along with examples for each. A summary table is also provided to illustrate the results of different assignment operations when starting with a variable value of 10.

Uploaded by

kalpanapriyam213
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

What Are Assignment Operators?

Assignment operators are used to assign values to variables.


They can also combine assignment with arithmetic operations.

Types of Assignment Operators in Python


Operator Description Example
= Assign a = 5
+= Add and assign a += 3 → a = a + 3
-= Subtract and assign a -= 2 → a = a - 2
*= Multiply and assign a *= 4 → a = a * 4
/= Divide and assign a /= 2 → a = a / 2
//= Floor divide and assign a //= 2
%= Modulus and assign a %= 3
**= Exponentiate and assign a **= 2

Step-by-Step Examples
1. Simple Assignment (=)
a = 10
print("a =", a) # Output: 10

2. Add and Assign (+=)


a = 10
a += 5 # Same as a = a + 5
print("a =", a) # Output: 15

3. Subtract and Assign (-=)


a = 15
a -= 3 # Same as a = a - 3
print("a =", a) # Output: 12

4. Multiply and Assign (*=)


a = 4
a *= 3 # Same as a = a * 3
print("a =", a) # Output: 12

5. Divide and Assign (/=)


a = 12
a /= 4 # Same as a = a / 4
print("a =", a) # Output: 3.0

6. Floor Divide and Assign (//=)


a = 12
a //= 5 # Same as a = a // 5
print("a =", a) # Output: 2

7. Modulus and Assign (%=)


a = 13
a %= 4 # Same as a = a % 4
print("a =", a) # Output: 1

8. Exponent and Assign (**=)


a = 3
a **= 2 # Same as a = a ** 2
print("a =", a) # Output: 9

Summary Table
Expression Same As Result (if a=10)
a = 10 Assign 10
a += 5 a = a + 5 15
a -= 3 a = a - 3 12
a *= 2 a = a * 2 24
a /= 4 a = a / 4 6.0
a //= 3 a = a // 3 2
a %= 2 a = a % 2 0
a **= 3 a = a ** 3 8 (if a=2)

You might also like