The value of the expression conv(celcius) is whatever you write after return in the conv() function. If there is no return statement, then a function defaults to returning None.
Consider the difference between these kinds of functions:
# A function that returns a value
# Doesn't "do" anything, only useful for what it returns
def square_of(x):
return x * x
# You can do stuff with the return value:
result = square_of(4)
print(result) # 16
print(result + 1) # 17
#################################################
# A function that "does stuff" rather than returning anything useful
def print_the_square_of(x):
print("Computing the square...")
square = x * x
print(square)
print("Finished computing the square.")
# No return statement is equivalent to "return None" here.
print_the_square_of(10) # the stuff happens when you call it
The print() function is just another function, and it’s the kind of function that “does stuff” and returns None rather than returning anything useful.
Occasionally, a function will both “do stuff” (the term is side effects) and return a useful value:
def compute_cube(x):
print("Computing the cube...")
return x * x * x
cube = compute_cube(3) # prints "Computing the cube..."
print(cube) # prints 27
print(cube + 1) # prints 28
In future, please don’t post screen shots of code, please copy and paste
the text into your message.
You have two issues here.
When Python runs a function, when it gets to the very end of the
function and “falls off the end”, that’s the same as return None. So
by default, any function will return None unless you explicitly return
another value.
The other issue is that print is not return. print just prints the value
to the screen. To actually return a value, you must use return. Any
code after the return will not be run (because the function has
returned control to where it came from) and is called “dead code”.
Compare these two functions and see the difference in how they behave:
def demo1():
print("printing one")
print("and two")
print("and three")
return "done"
value = demo1()
print("The returned value is", value)
def demo2():
return "returning one"
return "and two"
return "and three"
print("done")
value = demo2()
print("The returned value is", value)