Programming with Python

⌘K
  1. Home
  2. Docs
  3. Programming with Python
  4. Variables, Expression and...
  5. Operators and Types of Op...
  6. Assignment Operators

Assignment Operators

  • Assignment operators are used to assign values to variables
  • Consider a=2, b= 3, c= 4

Example

a=3
b=2
c=a+b
print("c=",c)
a+=b
print("a+=b",a)
a-=b
print("a-=b",a)
a*=b
print("a*=b",a)
a/=b
print("a/=b",a)
a%=b
print("a%=b",a)
a**=b
print("a**=b",a)
a//=b
print("a//=b",a)

Output

('c=', 5)
('a+=b', 5)
('a-=b', 3)
('a*=b', 6)
('a/=b', 3)
('a%=b', 1)
('a**=b', 1)
('a//=b', 0)

Loading

Views: 2

How can we help?

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments