no side effects

Michele Simionato mis6 at pitt.edu
Wed Jan 8 08:10:04 EST 2003


I was surprised by the following code:

>>> for i in [1,2,3]:
...     print i,
...     i=3

I would have expected only 1 to be printed, but instead Python
continues the loop without noticing that the value of i has
changed. IOW, no side effect.
I am not against that (I am even in favor), but it fooled my 
intuition coming from other languages.
Maybe others will appreciate that.

Cheers,

--
Michele Simionato - Dept. of Physics and Astronomy
210 Allen Hall Pittsburgh PA 15260 U.S.A.
Phone: 001-412-624-9041 Fax: 001-412-624-9163
Home-page: http://www.phyast.pitt.edu/~micheles/




More information about the Python-list mailing list