Introduction
Function basics
More advanced concepts
Summary

Instruction

Perfect! Another interesting concept related to functions is None. It is a value you may return when you mean "nothing". For instance:

def safe_division(x, y):
  if y == 0:
    return None
  else:
    return x/y

The function above takes two numbers and divides the first one by the second one... unless the second number is 0! Division by 0 is not allowed, so we would normally end up with an error. Our function, however, returns a None value instead to signify that the operation is not possible.

As you saw earlier in this part, None is also returned when the programmer does not provide a return statement at all.

Note that in most other languages, the null keyword is used instead of None.

Exercise

Run the template code.

As you can see, we invoke safe_division twice. The first time, we get standard division. The second time, we provide a 0, so we get None as the output.