@Alan
@Dave
@Dominik
thank you all so much for the elaborate explanations! It's really
simple and crystal clear now, the most difficult part was actually to
detect and overcome my own misconceptions. Once I did that, the rest
was really easy. Kind of a valuable learning for the future ;-)
Instead
Hej there,
I am making a couple wrong assumptions about the program below, but I
do not know where my thinking mistake is. I have some trouble
understanding what exactly happens within this loop here:
a, b = 0, 1
while b 10:
print(b)
a, b = b, a +b
What I would expect as an outcome of
Hi,
a, b = b, a +b
a = b = 1
b = a + b = 1 + 1 = 2
Your issue is that you interpret the assignment wrong. You seem to think
that it assigns b to a and THEN a+b to b, which is not the case. The
right side of the assignment creates a tuple, and the left side unpacks
it. It is the same as:
On Sun, 24 Nov 2013 11:24:43 +0100, Rafael Knuth
rafael.kn...@gmail.com wrote:
a, b = b, a +b
a = b = 1
b = a + b = 1 + 1 = 2
I suggest you play with the statement a bit. Print out both values
each time through the loop.
The expression b, a+b produces a tuple. The left side a, b
Now I got it, thanks :-)
a, b = b, b + a
... I was was wrongly assuming that a and b on the left side talk to
each other and that a tells b something like: Hey 'b' ... I just
assigned another value to you, make sure you execute it. But a and b
don't talk to each other. Each of them executes
On 24/11/13 13:05, Rafael Knuth wrote:
a and b on the left side are unchangable tuples and they simply get
unpacked on the right side.
Be careful about terminology here. a,b is a single tuple with two
values. But a and b are variables not tuples.
Tuples are collections of (one or more)
]
Date: Thu, 3 Jul 2008 12:59:39 +1200
From: [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Subject: Re: [Tutor] Fibonacci series(perhaps slightly off topic)
CC: tutor@python.org
On 03/07/2008, Emil wrote:
I have created a class called Fibs which allow you
):
self.fibsseq.append(self.fibsseq[-1] + self.fibsseq[-2])
return self.fibsseq[key]
Date: Thu, 3 Jul 2008 12:59:39 +1200
From: [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Subject: Re: [Tutor] Fibonacci series(perhaps slightly off topic)
CC: tutor@python.org
On 03/07/2008
Hello all
I have created a class called Fibs which allow you to access a specific number
in the Fibonacci series(http://en.wikipedia.org/wiki/Fibonacci_number) But it
seems to me that it is a bit inefficient, any suggestions on how to make it
more efficient?
Here is the code:
class
On 03/07/2008, Emil [EMAIL PROTECTED] wrote:
I have created a class called Fibs which allow you to access a specific
number in the
Fibonacci series(http://en.wikipedia.org/wiki/Fibonacci_number) But it seems
to me that it
is a bit inefficient, any suggestions on how to make it more
10 matches
Mail list logo