Python Forum

Full Version: Print gives none
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Dear forum,

Could you pls advise why this code gives none

list=["a","b"]
print(list.append(list[1]))
And the following code works fine:

list=["a","b"]
list.append(list[1])
print(list)
list.append() method works in-place, i.e. it does not return the modified list as you expect. It returns None, like any other function that does not return something explicitly.
By the way list is built-in function. don't use it as variable name