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 trialvikas pal
11,563 Pointscan'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
Treehouse TeacherHi there! I wrote a little example here to help explain:
def multiply(x,y):
return x * y
result = multiply(7, 10)
print(result)
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!
vikas pal
11,563 Pointsvikas pal
11,563 Pointsthanks a lot i know you helped me one more time
vikas pal
11,563 Pointsvikas pal
11,563 Pointshii jennifer please add me on twitter