When writing functions, it's very useful to follow guidelines so that you write them well. I'll quickly point some of them out here:
False
or None
is not the same thing, even if within a Boolean context they both evaluate to False
. False
means that we have information (False
), while None
means that there is no information. Try writing functions which return in a consistent way, no matter what happens in their body.numbers
is not sorted by the sorted
function, which actually returns a sorted copy of numbers
. Conversely, the list.sort()
method is acting on the numbers
object itself, and that is fine because it is a method (a function that belongs to an object and therefore has the rights to modify it):>>> numbers = [4, 1, 7, 5] >>> sorted(numbers) # won't sort the original `numbers` list [1, 4, 5, 7] >>> numbers # let's verify [4, 1, 7, 5] # good, untouched >>> numbers.sort() # this will act on the list >>> numbers [1, 4, 5, 7]
Follow these guidelines and you'll write better functions, which will serve you well.