Help ! newbie problem

Batista, Facundo FBatista at uniFON.com.ar
Fri Dec 26 16:30:00 EST 2003


ferdydurke wrote:

#- I am trying to learn python... I can't explain the 
#- difference beetween these
#- two programms, Fibonacci suites :
#- 
#- 
#- >>> a,b,c = 1,1,1
#- >>> while c<12:
#- ...     print b,
#- ...     a,b,c = b,a+b,c+1
#- ...
#- 1 2 3 5 8 13 21 34 55 89 144
#- 
#- and
#- 
#- >>> a,b,c = 1,1,1
#- >>> while c<12:
#- ...     print b,
#- ...     a=b
#- ...     b=a+b
#- ...     c=c+1
#- ...
#- 1 2 4 8 16 32 64 128 256 512 1024

In the first case, the operations at the right side of the "=" are done
before rebinding ("changing the value") of the objects at the left of the
"=".

In the second case, when you do "b=a+b", it's not the original "a", because
you already done "a=b".

See:

>>> a,b,c = 1,1,1
>>> while c<4:
	print b
	a,b,c = b,a+b,c+1
	print id(a), id(b), id(c)

	
1
7677952 7676944 7676944
2
7676944 7684064 7684064
3
7684064 7682048 7683056

>>> a,b,c = 1,1,1
>>> while c<4:
	print b
	a = b
	b = a+b
	c = c+1
	print id(a), id(b), id(c)

	
1
7677952 7676944 7676944
2
7676944 7683056 7684064
4
7683056 7687152 7683056

>>> id(1)
7677952
>>> id(2)
7676944
>>> id(3)
7684064
>>> id(4)
7683056

.	Facundo





. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . .
ADVERTENCIA  

La información contenida en este mensaje y cualquier archivo anexo al mismo,
son para uso exclusivo del destinatario y pueden contener información
confidencial o propietaria, cuya divulgación es sancionada por la ley. 

Si Ud. No es uno de los destinatarios consignados o la persona responsable
de hacer llegar este mensaje a los destinatarios consignados, no está
autorizado a divulgar, copiar, distribuir o retener información (o parte de
ella) contenida en este mensaje. Por favor notifíquenos respondiendo al
remitente, borre el mensaje original y borre las copias (impresas o grabadas
en cualquier medio magnético) que pueda haber realizado del mismo. 

Todas las opiniones contenidas en este mail son propias del autor del
mensaje y no necesariamente coinciden con las de Telefónica Comunicaciones
Personales S.A. o alguna empresa asociada. 

Los mensajes electrónicos pueden ser alterados, motivo por el cual
Telefónica Comunicaciones Personales S.A. no aceptará ninguna obligación
cualquiera sea el resultante de este mensaje. 

Muchas Gracias.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20031226/4cfeb394/attachment.html>


More information about the Python-list mailing list