Can someone explain the difference between Return values and Print.
If in a Python function and I want to return a value does it have to be a number or could it be anything? Please provide example,
Can someone explain the difference between Return values and Print.
If in a Python function and I want to return a value does it have to be a number or could it be anything? Please provide example,
I believe return() is specific to being used within functions, and that you can include anything printable as an argument. For example,
x = 7
return(x)
would return an error, whereas
x = 7
print(x)
or
def printx(X):
return(X)
should be fine. Specifically, return() is used to end the execution of a function; nothing after a return() statement will be executed. More information can be found here: https://www.geeksforgeeks.org/python-return-statement/#:~:text=Python%20return%20statement,return%20statements%20are%20not%20executed.