Why Does This Print Statement Not Execute?

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
    return "Nope"

“something” used in the print statement doesnt print

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?

Could you please help me with this. I wanted to print the result and it didn’t work… why?

def distance_from_zero(d):
if type(d) == int or type(d) == float:
return abs(d)
return “Nope”

print distance_from_zero(3)

difficult to say, please format your code:


It seems that the function call (which should execute the function) is nested within the function, which won’t work. The function has to be outside/after the function.