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?
2 Answers
+ 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.
+ 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
>>>