Hi Michaelle, and welcome.
On Wed, Aug 19, 2015 at 12:09:15PM -0400, Michelle Meiduo Wu wrote:
> Hi there, I'm trying to use List in a function. But it doesn't work.
> Here are sample code not work:
> ---------------------------------------
> def getResult():
> ls = []
> ls = ls.append(100)
That line above is your problem. The append() method should be thought
of as a procedure that acts in place, not a function which returns a
value. So the line:
ls = ls.append(100)
sets ls to None, a special value that means "no result". Instead, you
should write this:
def getResult():
ls = []
ls.append(100)
ls.append(200)
return ls
Or you can make that even shorter:
def getResult():
ls = [100, 200]
return ls
--
Steve
_______________________________________________
Tutor maillist - [email protected]
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor