How to handle functions return value in Python

Viewed 9048

The function multiply_by_ten takes a numeric argument, multiplies it by ten and returns the result back. Before this function performs its multiplication it checks if the argument is a numeric. If the argument is not numeric, the function prints out the message notifying that the argument is not a digit and returns None.

Question. Some developers believe that any given function should be returning the same type of value regardless of the circumstances. So, if I would follow a such opinion then this function should not be returning None. How to handle a situation like this? Should the argument be checked before it is being sent to a function? Why?

 def multiply_by_ten(arg):
    if not str(arg).isdigit():
        print 'arg is not a digit'
        return
    return float(arg) * 10


result = multiply_by_ten('abc')
6 Answers
Related