Purify.. Your code looks a bit off--it threw a "'NoneType' object has no attribute 'append'" error


#1

Can any body help me? can not find the problem:

Your code looks a bit off--it threw a "'NoneType' object has no attribute 'append'" error


#2

result = result.append(item)

you assign result.append(item) to result

can i know why did you do so?


#3

Hey,

Can I know why we can not put "result= result.append(item))"?
I removed the "result=" part and it works.

Thanks for your help,
Regards,
Hang


#4

most welcome :slight_smile:

why do you need to do so?
if you're asking me this so i can assume you dont know what append method does.go to the lesson where you learned about it.then ask me if you've any question.you should understand your code than just write it.

run and understand it

def p(n):
  r=[]
  for i in n:
    if i%2==0:
      r.append(i)
  return r
print p([5,1,2,4,8,9])

#5

Hi,
Thanks very much. I understand better now!


#6

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.