aTup = (1,2,3)
print(list(aTup).append(4))
Why does it display None
?
aTup = (1,2,3)
print(list(aTup).append(4))
Why does it display None
?
append
returns None
, simple as that. It does however modify the list
>>> l = [1,2,3]
>>> print(l.append(4))
None
>>> l
[1, 2, 3, 4]
The reason is that it isn't meant to be called with the return value used mistakenly for an assignment.
l = l.append(4) # this is wrong
It's because the method append()
does not return any value.
If you want to print the list after the update, you can do the following:
aTup = (1,2,3)
aList = list(aTup)
aList.append(4)
print(aList)