I've just started learning python a few weeks back, one of the first things that was taught was how to manipulate lists. Normally if I have a list and want to append a new element it would look something like this.
test_list=[1,2,3]
test_list.append(4)
I just wanted to know why we don't instead say
test_list=test_list.append(4)
This thought came to me because normally for a variable 'x' if we want to update its value, we do the following:
x=initial_value
x=new_value
In the same way for the list case, doesnt test_list.apppend(4)
represent a list with the same elements of test_list
and contain an extra element 4? In which case why is it that we cant use the same syntax in both cases to update the variable storing the information? In the list case, if I try and print the list I get None
and in the x
case, if I print x
i get new_value
?