What is the difference between return and print?
<aside>
⚠️ If there is no return
value, Python automatically returns None
, so
return None
, return
, and simply nothing are the same
</aside>
<aside>
⚠️ If there is a return
statement (even if it is blank or returns None
), the function stops executing.
</aside>
The difference between return
and print
is that return
gives function(argument)
a value but print
just prints something to the console.
def a(x):
b=x # There is no return statement, returns None
print(a(3))
def a(x):
return
print("This line doesn't get executed") # Because there was a return
a(3)