Search code examples
pythonlistmethodsreversenonetype

why print statement return None, when we use method on the list in python


why does this code print None and

a = [1,2,3,4]
print(a.reverse())

while this will print a reversed list

a = [1,2,3,4]
a.reverse()
print(a) 

Solution

  • Because the function reverse doesn't return anything, ence why you get a None

    When you print(a.reverse()), you print the result of the function .reverse() on a, but reverse essentially modify "a" without returning anything