Welcome back everyone. This is the final tutorial in the subsection for functions, and we're going to be talking about return values from functions. Again, this may not be new to some of you as it is a fairly basic concept. So, in the past videos we have been using functions to print something out, but what if we want to return that value and do something else with it? Let's go ahead and define a function.
def do_math(num1, num2): return num1 + num2
do_math(5, 7)
Now when we run this bit of code, it's not going to print anything in our Python console because we didn't tell it to. Let's add on to this.
def do_math(num1, num2): return num1 + num2
math1 = do_math(5, 7) math2 = do_math(11, 34)
print("First sum is", math1, "and the second sum is", math2)
When we run this we get the First sum is 12 and the second sum is 45. So, again, this a very simple example, but we will expand on this when we build our calculator.
Get The Learn to Code Course Bundle!
https://josephdelgadillo.com/product/learn-to-code-course-bundle/
Best,
Joseph Delgadillo
Web: https://josephdelgadillo.com/
YouTube: https://www.youtube.com/c/JosephDelgadillo
Steemit: https://steemit.com/@jo3potato
I followed and upvote for you. I would be happy if you also help me. Thanks
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Congratulations @jo3potato! You have completed some achievement on Steemit and have been rewarded with new badge(s) :
Award for the number of upvotes
Click on any badge to view your own Board of Honor on SteemitBoard.
For more information about SteemitBoard, click here
If you no longer want to receive notifications, reply to this comment with the word
STOP
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit