[Tutor] About using list in a function

Michelle Meiduo Wu wumeid at hotmail.com
Wed Aug 19 18:09:15 CEST 2015

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)    ls= ls.append(200)      return ls
reList = []reList = getResult()lsLength = len(reList)print '\n The length of the list is:' + str(lsLength)-----------------------------------------I ran the above code, there is an error message: AttributeError: 'NoneType' object has no attribute 'append'
But the code below not using list in a function works.----------------------------------------------### This works:ls = []ls.append(100)ls.append(200)lsLength = len(ls)print '\n list length is: ' + str(lsLength)----------------------------------------------------- Do you know  the reason?
Thank you,Michelle


More information about the Tutor mailing list