Please explain this for me

Emeka emekamicro at gmail.com
Wed Dec 21 00:12:40 EST 2011


Noah, Calvin

Thanks so much!

Regards,
Emeka

On Wed, Dec 21, 2011 at 6:57 AM, Noah Hall <enalicho at gmail.com> wrote:

> On Wed, Dec 21, 2011 at 4:39 AM, Emeka <emekamicro at gmail.com> wrote:
> >
> > Hello All,
>
> > v = []
> >
> > def add_to_list(plist):
> >     u = plist.append(90)
> >     return u
> >
> > add_to_list(v)  # This function call returns nothing
> > Could someone explain why this function call will return nothing?
>
> It's because add_to_list returns the value returned from plist.append
> stored in u.
> append changes a list in place and returns nothing. Functions that
> return nothing return None. This is why it'll be None - u is None
> because append returns None.
>
>
> > add_to_list([])
> > This one returns nothing, why?
>
> It's because the object [] here has no name, so that you have no way
> to refer to it after the function changes it, since it changes it in
> place. It gets eaten by Python, never to be seen again.
>



-- 
*Satajanus  Nig. Ltd


*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20111221/fa94664e/attachment-0001.html>


More information about the Python-list mailing list