[Tutor] How default arg of function works

Deepak Dixit deepakdixit0001 at gmail.com
Thu Jun 14 07:01:24 EDT 2018


Thanks a lot for this information.

On Thu, Jun 14, 2018, 4:28 PM Alan Gauld via Tutor <tutor at python.org> wrote:

> On 14/06/18 08:40, Deepak Dixit wrote:
> > You mean that for default args and passed args of mutable type, python
> uses
> > different object and same reference will be used for further calling of
> the
> > function.
>
> Yes, the default argument object is created when the
> function is defined (ie before it is even called the
> first time) and the same reference to that obje3ct is
> always used for the default argument.
>
> When you provide the argument yourself Python uses
> whatever object you pass.
>
> > Now one more thing I want to ask you that how can I get deep
> understanding
> > of python like how list, dictionary works internally and other topics ,
> is
> > it only possible after more and more practice.
>
> - You can observe the behaviour as you have been doing.
> - You can use the disassembly module (dis) to look at
>   the object code generated by the compiler.
> - And, the ultimate truth, you can read the C source code
>   if you know C.
>
> And of course you can ask questions here. We have several
> contributers who understand Python internals quite well.
>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
> http://www.amazon.com/author/alan_gauld
> Follow my photo-blog on Flickr at:
> http://www.flickr.com/photos/alangauldphotos
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>


More information about the Tutor mailing list