0

HELP

x=[[],[],[]] x[0]=1 -> this I get x[2]=x[1].append(str(x[0])) -> this I totally don’t print(x) Result is: [1,[’1’], None] Why is it none? First [] becomes 1 Second [] becomes ’1’?? Third [] becomes ?? none? Why?

20th Dec 2018, 9:33 AM
Elis Belen
2 odpowiedzi
+ 4
x[1].append(str(x[0])) appends the string value of x[0] to x[1], and does nothing else. Meaning, it doesn't return anything. So when you set the value of x[2] to that, it becomes None.
20th Dec 2018, 10:06 AM
blackcat1111
blackcat1111 - avatar
+ 2
append is a list method that modifies a list but returns nothing (None). in other words, its result is a modified list itself, it has nothing to return. >>> a=[1] >>> b=2 >>> c=a.append(b) >>> print(a) [1, 2] >>> print(c) None >>>
20th Dec 2018, 10:08 AM
strawdog
strawdog - avatar