Videos
thank you all for explaining this to me. i think im understand what it does now
A return is used when you want to stop a function from executing further. The first one is necessary in order to not have the statements after the if self.head is None block be executed. The second one is unnecessary, as it's at the end of the function, so the function will return regardless. It's just a more explicit way of saying "I am returning here, but am not returning anything". That's the default behavior of any function that you don't explicitly put a return into.
It's very common in programming languages to have explicit, blank returns. For instance in C, any function whose return type is void has to have any returns be empty. In Python there's tons of built-in functions that don't need to return anything, let alone all the custom ones one might create. For instance, list.append() returns None; which is what any function in Python returns by default when there's not anything explicitly being returned.
The first return in prepend is an early return and this is the only way of returning from this point in the function as it is currently written.
The second return is entirely redundant and can be removed.