Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The difference between '+=' and '=+'? [duplicate]

I have a simple piece of code that prints out the integers 1-10:

i = 0
while i < 10:
    i += 1
    print(i)

Then if you just change one operator around on line 3, it prints out an infinite amount of 1 integers (which I understand why it does that).

Why isn't a syntax error occurring when running this second program? Wouldn't it call a syntax error in the event of an assignment operator being followed by an addition operator?

i = 0
while i < 10:
    i =+ 1
    print(i)
like image 714
faceless Avatar asked Nov 16 '16 23:11

faceless


People also ask

What is the difference between duplicate and duplicate?

Duplicate's noun and adjective forms are related—a duplicate is an exact copy of something, and as an adjective, duplicate refers to the quality of being an exact copy.

Is duplicate the same?

What is a Duplicate? The word duplicate is often used in the sense of 'an identical copy. ' To make a duplicate, you usually need the original.

What is the difference between copy paste and duplicate commands?

Duplicate (Ctrl-D) will automatically copy and paste whatever slide you select and place it right below the original slide. It will be identical in every way to the previous slide. Copy, (Ctrl-C) will save a copy of the slide to your clipboard so that it can be pasted (Ctrl-V) elsewhere in the presentation.

Whats the difference between copy and duplicate on a Mac?

Duplicate is almost the same as Copy, except that the copy is created in the same location as the original and assigned a new name. To do this, choose the Duplicate command (Command-D) from the Finder's File menu. The copy will have the word copy appended to its name.


1 Answers

i+=1 is the same as i=i+1, whereas i=+1 just means i=(+1).

like image 114
Kittsil Avatar answered Oct 12 '22 15:10

Kittsil