Skip to main content
Home
  • Tutorials
    • Quality Assurance
    • Software Development
    • Machine Learning
    • Data Science
  • About Us
  • Contact
programsbuzz facebook programsbuzz twitter programsbuzz linkedin
  • Log in

Main navigation

  • Tutorials
    • Quality Assurance
    • Software Development
    • Machine Learning
    • Data Science
  • About Us
  • Contact

Python: Assignment Operators

Profile picture for user devanshi.srivastava
Written by devanshi.srivastava on 06/25/2021 - 20:42

Assignment Operators is used to assign values to the variable.

Operator Description Syntax
Equal (=) It assign value of right side of expression to left side operand. a = b + c
Add AND(+=) It add right side operand with left side operand and then assign to left operand.

a += b

a = a + b

Subtract AND(-=) It subtracts right operand from the left operand and assign the result to left operand.

a -= b

a = a - b

Multiply AND(*=) It multiplies right operand with the left operand and assign the result to left operand.

a *= b      

a = a * b

 Divide AND(/=) It divides left operand with the right operand and assign the result to left operand.

a /= b        

a = a / b

Modulus AND(%=) It takes modulus using two operands and assign the result to left operand.

a %= b  

a = a % b

Exponent AND(**=) It performs exponential on operators and assign value to the left operand.

a **= b    

a = a ** b

Floor Division(//=) It performs floor division on operators and assign value to the left operand.

a //= b      

a = a // b

Bitwise AND(&=) It performs Bitwise and on operands and assign value to left operand.

a &= b        

a = a & b

Bitwise xOR(^=) It performs Bitwise xOR on operands and assign value to left operand.

a ^= b      

a = a ^ b

Bitwise OR(|=) It performs Bitwise OR on operands and assign value to left operand.

a |= b        

a = a | b

Bitwise Right Shift (>>=) It performs Bitwise right shift on operands and assign value to left operand.

a >>= b  .

 a = a >> b

Bitwise Left Shift(<<=) It performs Bitwise left shift on operands and assign value to left operand.

a <<= b

a= a << b

Example:

a = 4
b = 3

d = e = f = 0
g = h = i = j = 2
k = l = m = n = o = 3

c = a + b
print("c = ",c)

d += a
print("d = ",d)

e -= b
print("e = ",d)

f *= a
print("f = ",f)

g /= b
print("g = ",g)

h %= b 
print("h = ",h)

i **= a
print("i = ",i)

j //= a 
print("j = ",j)

k &= b
print("k = ",k)

l ^= b 
print("l = ",l)

m |= b
print("m = ",m)

n >>= b
print("n = ",n)

o <<= a
print("o = ",o)

Output:

c =  7
d =  4
e =  4
f =  0
g =  0.6666666666666666
h =  2
i =  16
j =  0
k =  3
l =  0
m =  3
n =  0
o =  48
Related Content
Python Tutorial
Python: Operators, Operands and Operators Types
Python: Arithmetic Operators
Tags
Python
  • Log in or register to post comments

Choose Your Technology

  1. Agile
  2. Apache Groovy
  3. Apache Hadoop
  4. Apache HBase
  5. Apache Spark
  6. Appium
  7. AutoIt
  8. AWS
  9. Behat
  10. Cucumber Java
  11. Cypress
  12. DBMS
  13. Drupal
  14. GitHub
  15. GitLab
  16. GoLang
  17. Gradle
  18. HTML
  19. ISTQB Foundation
  20. Java
  21. JavaScript
  22. JMeter
  23. JUnit
  24. Karate
  25. Kotlin
  26. LoadRunner
  27. matplotlib
  28. MongoDB
  29. MS SQL Server
  30. MySQL
  31. Nightwatch JS
  32. PactumJS
  33. PHP
  34. Playwright
  35. Playwright Java
  36. Playwright Python
  37. Postman
  38. Project Management
  39. Protractor
  40. PyDev
  41. Python
  42. Python NumPy
  43. Python Pandas
  44. Python Seaborn
  45. R Language
  46. REST Assured
  47. Ruby
  48. Selenide
© Copyright By iVagus Services Pvt. Ltd. 2023. All Rights Reserved.

Footer

  • Cookie Policy
  • Privacy Policy
  • Terms of Use