Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #17646

Re: Please explain this for me

References <CAOypoo4YZUF9AWJVmL+7Po5Ew_fLyzyJmsA3b1qM8OJhNu0UXg@mail.gmail.com>
From Noah Hall <enalicho@gmail.com>
Date 2011-12-21 04:57 +0000
Subject Re: Please explain this for me
Newsgroups comp.lang.python
Message-ID <mailman.3902.1324443488.27778.python-list@python.org> (permalink)

Show all headers | View raw


On Wed, Dec 21, 2011 at 4:39 AM, Emeka <emekamicro@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.

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Please explain this for me Noah Hall <enalicho@gmail.com> - 2011-12-21 04:57 +0000

csiph-web