-10

for example

A+=A=a

output:

IndentationError: unindent does not match any outer indentation level

in the same time with B+=B+b is working fine!

so whats the difference between = and += with Python

jamylak
  • 128,818
  • 30
  • 231
  • 230
Nomea
  • 1
  • 2

4 Answers4

0

A += 1 means A = A + 1. So A += A = a would be A = A + A = a (which obviously doesnt work).

The error you seem to experience is not caused by this operator. Perhaps you mixed spaces with tabs, or you simply did not indent a certain line when it should have been.

TerryA
  • 58,805
  • 11
  • 114
  • 143
0

A = a It's a simple assignment, while A += a Is equivalent to

A = A + a

This occurs in most programming languages

DevGar
  • 1
  • 1
0

a += a would be read

a is a plus a

Therefore, A += A is

A is A plus A

A += A is short for A = A + A

The exception has nothing to do with your operator layout.

Community
  • 1
  • 1
Mr_Spock
  • 3,815
  • 6
  • 25
  • 33
0
  1. what do you mean to do with A+=A=a? Make sure your purpose before you do anything.
  2. try to do your job step by step, instead of get the whole piece at once.
  3. a += 1 equals a = a + 1, that's the meaning and usage of +=.
Shady Xu
  • 5,527
  • 2
  • 14
  • 18