python - why [].append(1) is None -


this question has answer here:

i use python this

>>>print [].append(1) none  >>>ls = [] >>>ls.append(1) >>>ls [1] 

why "[].append(1)" value none ,and other 1 real value?

because append() list method doesn't return list, modifies list called on. in case, anonymous list modified , thrown away.

the documentation isn't super-clear, says is:

list.append(x)

add item end of list; equivalent a[len(a):] = [x].

for other methods, such list.count(x), word "return" occurs in description, implying if doesn't, method doesn't have return value.


Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -