Posted on

Learn Python Episode #20: Return Values from Functions

Get The Learn to Code Course Bundle!
https://josephdelgadillo.com/product/learn-to-code-course-bundle/

Enroll in The Complete Python Course on Udemy!
https://www.udemy.com/python-complete/?couponCode=PYTHONWP

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.

Web – https://josephdelgadillo.com/
Subscribe – https://goo.gl/tkaGgy
Follow for Updates – https://steemit.com/@jo3potato