default argument values qns

Fredrik Lundh fredrik at pythonware.com
Thu Jun 1 09:50:20 EDT 2006


micklee74 at hotmail.com wrote:

> i have declared a function like this:
>
> def aFunction ( arg1 , arg2 = 0):
>         ....
>         print type(arg2)
>
> when i try to print the type of arg2, it gives me 'str' type..why is it
> not integer type, since i have declared it as 0 ??

because you or someone else is passing in a string as the second argument,
perhaps?

>>> def aFunction(arg1, arg2=0):
...     print type(arg2)
...
>>> aFunction(1)
<type 'int'>
>>> aFunction(1, 2.0)
<type 'float'>
>>> aFunction(1, "two")
<type 'str'>

</F> 






More information about the Python-list mailing list