On Mon, Apr 25, 2011 at 9:59 AM, Prasad, Ramit <ramit.pra...@jpmchase.com>wrote:
> >> while numberOfGrades != gradesEntered: > >> grade = int(raw_input("Please enter the grade:" )) > >> gradesEntered += 1 > >> score =+ grade > > >Note that += and =+ do different things. I suspect this last line is > >not doing what you think. Details like this are very important in > >programming, especially since both forms are valid code, they > >just do different things! > > Could you please expand on that? From playing around on the shell it looks > like 'B =+ 2 ' always sets B to 2. At first, I thought it was taking it as > 'B=None+2' but that gave me the error "TypeError: unsupported operand > type(s) for +: 'NoneType' and 'int'" So what is actually going on behind the > scenes? > > Ramit > += is a single operator that is equivalent to typing b = b + 2 =+ is two operators put together: b+=2 is equivalent to b += 2 is equivalent to b = b + 2 b=+2 is equivalent to b = +2 is equivalent to b = 2 b = + 2 is legal syntax, while b + = 2 is not. HTH, Wayne
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor