Sometimes the tutorial teaches to use ‘return’ after a function is created. I am not sure what it does.
I think it’s time someone introduced you to https://www.google.com
:^)
And also, if you think about what functions do, that should let you make a pretty good guess about what return
does.
def two_plus_two()
print(2+2)
This one will print to your screen 4
def two_plus_two()
2+2
This one does 2+2 and just throws away the 4
def two_plus_two()
return 2 + 2
This one hands the value 4 back to the caller
I can use that 4 in other parts of my program now
i.e. 4 + two_plus_two() = 8
or if (two_plus_two > 3)
2 Likes
You don’t always want to print everything on the screen.
def plus_two(integer):
x = integer + 2
return x
After you use this function:
plus_two(5)
The value of x will be saved in the memory and you can use it for later operations.
1 Like