Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Python Basics (2015) Logic in Python Fully Functional

can't understand function

I can't understand function and return .please tell me in brief about it .if somebody know tell me please.

1 Answer

Jennifer Nordell
Jennifer Nordell
Treehouse Teacher

Hi there! I wrote a little example here to help explain:

def multiply(x,y):
  return x * y

result = multiply(7, 10)

The function here is named multiply and it accepts two values. A function is simply a piece of code that we want to be run every time we call it. So in this simple example we have a a variable named result. We're going to call/invoke/execute the multiply function and we're going to send in a 7 and a 10. The values 7 and 10 will come into the function and we are now accessing them with the names x and y. We multiply them together and return the result. We're returning the value to the original piece that called it. Which is multiply(7,10). This will now put 70 into the variable result. Now when we print the value of result to the screen, it will print 70.

Hope this helps! :sparkles:

thanks a lot i know you helped me one more time

hii jennifer please add me on twitter