Q:

Why this insertion sort algorithm outputs None?

def insertion_sort(list):
    for index in range(1,len(list)):
        value = list[index]
        i = index - 1
        while i>=0:
            if value < list[i]:
                list[i+1] = list[i]
                list[i] = value
                i = i - 1
            else:
                break

a = [7,1,3,5,9,2,3]

print(insertion_sort(a))

This code is taken from a Khan Academy video. However, when I try to run it myself both on Jupyter Notebook and IDLE it outputs None. I can't figure out why when it's exactly the same from the video.
Thanks in advance for helping.

A:

Your function doesn't have a return statement anywhere. If a function doesn't return anything explicitly, it always returns None.
And it's almost certainly intentional that this function doesn't return anything.

Notice that the function mutates its argument in-place:
>>> a = [7,1,3,5,9,2,3]
>>> insertion_sort(a)
>>> a
[1, 2, 3, 3, 5, 7, 9]

In Python, it's idiomatic for functions that do this to not return anything. See, for example, builtin methods like list.sort and list.append.
And notice that in the cited video, this is exactly what the instructor does—they don't print the result of insertion_sort, they just call it, and then look at the value of the variable.

Also, in general, functions that mutate a value in-place, like this one, take an imperative verb, like the list method sort, while functions that leave the argument unchanged but return a transformed value, take a past participle, like the built-in function sorted.
So, if this function were named insertion_sorted, Python programmers would expect it to leave its argument alone and return a new, sorted list; since it's named insertion_sort, they'll expect it to sort its argument in-place and return nothing.

