A=['1']
C=A.append('1')
print C
Why is the above code return None but not ['1', '1'] in Python ?
A=['1']
C=A.append('1')
print C
Why is the above code return None but not ['1', '1'] in Python ?
The reason why you are not getting anything back is because the append method has no return value.
You could do:
A=['1']
C=A
C.append('1')
print(C)
Then you should get the right answer for your case that you are expecting to get.
In Python, the append
method mutates the list it was called on but does not return it. There's not much reason to either, since you already have a reference to the list.