Why does my print function return "None" when I run the code?

The question is " Write a function named append_sum that has one parameter — a list named named lst .

The function should add the last two elements of lst together and append the result to lst ."
My solution is following here:

def append_sum(lst):
x = lst.append(lst[-1] + lst[-2])
return x

print(append_sum([1, 1, 2]))

Instead of printing 3, ‘None’ get printed. Can someone help me in this regard?

.append() appends to the list in memory. The append method doesn’t return anything, so you get None (the absence of a return value)

1 Like