Solved Why does sort() return None? TOTomBeckerOP 5 Oct, 18:17 Seems like it would be more useful to return the list.
SASamPrice6 Oct, 07:32 Solutionreplies: 2It's a deliberate signal: methods that modify an object in place return None, so you don't confuse them with functions that return a new object. If you want a new sorted list, use sorted().
Comments 4
Join the discussion CommentAlready have an account? Log in
It's a deliberate signal: methods that modify an object in place return None, so you don't confuse them with functions that return a new object. If you want a new sorted list, use
sorted().So None means "I changed the original".
random.shufflereturning None got me once. Same lesson.Same for
append(),reverse(),shuffle()... all None.