Why Does This Print Statement Not Execute?


#1

why does the print statement not execute when used within a function

 def distance_from_zero(d):
  if (type(d)==int or type(d)==float):
    return abs(d)
    print something
  else:
    return "Nope"
  distance_from_zero(20)

“something” used in the print statement doesnt print


FAQ: Learn Python: Functions - Review: Built-In Functions
#2

By default, a function returns None at the end of the function. If we want to return something else at the end of the function, we can use the return keyword.

Given return is the last thing a function does, when a return keyword is reached, the function ends

so it never reached the print statement. Beside, something is a undefined variable at the moment, shouldn’t it be a string?

Also, why place the function call inside the function body?