What happens when returning a reversed list like this
python, return, return-value
Solution
`list.reverse` method doesn't return anything. It works over the elements on the list to which is applied (modifying the list). Hence, returning its result will return `None`. Here's the prof:
>>>[].reverse() == None
True
If you're trying to return a new list with element in reverse order, this is how you do it:
return list[::-1]
This is called `slicing` in Python and it's used to work with collections.
A small note about returning none: These methods don't actually `return None`. They don't return any value. But the result of evaluating a function that doesn't return any values is actually `None` in Python.
Hope this helps!
Problem
I used this code to return a list say [1,2,3,4] ``` return (list.reverse()) ``` But it simply wont return the correct result. I had to use ``` list.reverse() return list ``` why is this happening? and when I break up my issue and do ``` list1 = list.reverse() ``` in console and print list1, it simply prints "list1" p.s:- I am a beginner and still learning python.