+ 3

Python - Why is arr.sort() None?

arr = [34, 67, 34] print(arr.sort()) print(sorted(arr))

1st May 2019, 3:31 PM
Paolo De Nictolis
Paolo De Nictolis - avatar
1 Answer
+ 5
arr.sort() modifies the list in place and doesn't return anything (when this happens Python adds a "return None"). It's supposed to be used alone: arr.sort() # No print https://www.quora.com/What-is-the-difference-between-sort-and-sorted-function-in-Python
1st May 2019, 3:32 PM
Diego
Diego - avatar