Header Ads Widget

⚡ Premium Tools Hub • EXE Apps + Full Python Source Code
Lite • Pro • Bundle Packs • Instant Download

🐍 Python – Assignment Operators (Complete Beginner Guide)

Python provides assignment operators that are used to assign values to variables and also update them in a shorter way.

In this post, we will learn Python Assignment Operators in detail with clear examples.


🧠 What are Assignment Operators?

Assignment operators are used to assign values to variables and modify them.

👉 In simple words:

  • They store values in variables
  • They help update values easily

⚙️ Types of Python Assignment Operators

Python supports multiple assignment operators.


= 1. Simple Assignment (=)

Assigns a value to a variable.

Example:

x = 10
print(x)

+= 2. Add and Assign (+=)

Adds value and assigns result back to variable.

Example:

x = 10
x += 5
print(x)

Output:

15

-= 3. Subtract and Assign (-=)

Subtracts value and assigns result.

Example:

x = 10
x -= 3
print(x)

*= 4. Multiply and Assign (*=)

Multiplies value and assigns result.

Example:

x = 5
x *= 3
print(x)

/= 5. Divide and Assign (/=)

Divides value and assigns result.

Example:

x = 10
x /= 2
print(x)

%= 6. Modulus and Assign (%=)

Stores remainder.

Example:

x = 10
x %= 3
print(x)

**= 7. Exponent and Assign (**=)

Raises power and assigns result.

Example:

x = 2
x **= 3
print(x)

//= 8. Floor Division and Assign (//=)

Performs floor division.

Example:

x = 10
x //= 3
print(x)

📊 Python Assignment Operators Summary

Operator           ExampleMeaning
=           x = 10          Assign value
+=           x += 5          Add and assign
-=           x -= 5          Subtract and assign
*=           x *= 5          Multiply and assign
/=           x /= 5          Divide and assign
%=           x %= 5          Modulus and assign
**=           x **= 2          Power and assign
//=           x //= 2          Floor divide and assign

🚀 Where Assignment Operators are Used?

Assignment operators are used in:

  • Loops 🔁
  • Calculations ➗
  • Counters 📊
  • Data updates 🧾
  • Real-time applications ⚙️

🧪 Real Example: Counter Program

count = 0

count += 1
count += 1
count += 1

print(count)

🧾 Conclusion

Python assignment operators help you write shorter, cleaner, and more efficient code by updating variable values easily.


💡 Final Thought

If you master assignment operators, you can write faster and more professional Python code.




Post a Comment

0 Comments