Q from python tut...

prasad at my-dejanews.com prasad at my-dejanews.com
Tue May 25 06:28:06 EDT 1999


Hello,

I am learning python using the standard tut that came with the distri.
I know perl a little bit. Here are some of the things that I found
confusing till section 5.5.


val = '' or 'aa' or 'bb'
val gets the value 'aa'

shouldn't the expr '' or 'aa' or 'bb' evaluate to 0 or 1 and hence val
getting the value of 0 or 1.

------------------------------------------------------------

def f(a,l = none):
    if l is none:
        l = []
    l.append(a)
    return l

The above style has been recommended because by default, l will
accumulate the values from earlier calls. The above technique is
supposed to probably initialise it,if no value is passed for l.
but if nothing is passed for l in calling,the default should
automatically wipe out the earlier accumulated list. Then why is it that
the if loop has been specified?

It's been said that default values are evaluated only once, and at the
time of function defination. Does that mean that an argument of
modifiable type will get set to default only the first time and later
accumulate the earlier values from earlier calls?
If this is true,it seems like 'static' behaviour of C lang.

In general The mutable/non-mutable diff,the above static like nature of
mutables, evaluation of func. arg is rather confusing!!

Please help me in clearing the doubts.

Thanks in advance.

regards,
prasad.



--== Sent via Deja.com http://www.deja.com/ ==--
---Share what you know. Learn what you don't.---




More information about the Python-list mailing list