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


Groups > comp.lang.python > #17646 > unrolled thread

Re: Please explain this for me

Started byNoah Hall <enalicho@gmail.com>
First post2011-12-21 04:57 +0000
Last post2011-12-21 04:57 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

#17646 — Re: Please explain this for me

FromNoah Hall <enalicho@gmail.com>
Date2011-12-21 04:57 +0000
SubjectRe: Please explain this for me
Message-ID<mailman.3902.1324443488.27778.python-list@python.org>
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.

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web