[Tutor] exercise correct ??
ALAN GAULD
alan.gauld at btinternet.com
Tue Sep 7 09:52:38 CEST 2010
Oke, the 4 is a starting point for the index.
>
>Next problem.
>
>The begin looks like this :
>
> index_of(5, (1, 2, 4, 5, 6, 10, 5, 5), 4)
>
>But in the module I get this result :
>
>val = 5
>seq = (1, 2, 4, 5, 6, 10, 5, 5
>
>So the 4 is not avaible anymore.
>
Yes it is. It is the start parameter.
The function definition is
def index_of(val, seq, start=0):
val is the first value, 5, seq is the tuple and start is 4.
Now I can change the header to index(val, seq, start=0) to index (val, seq,
start)
>But I think that's not what the exercise wants.
>
Why would you want to do that? It would force you to provide a start value
for every call. The point of having a default value (=0) is so that you do not
need to specify start every time you use the function. But eveb if you do not
use the start value it will still have a value, 0.
There is no difference, you can access it exactly like the other parameters.
Just use its name.
HTH,
Alan G.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100907/09aea51a/attachment.html>
More information about the Tutor
mailing list