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 trialDarrin Spell Jr
Full Stack JavaScript Techdegree Student 10,303 PointsHow do I store the value from the function call?
I'm not understanding how to store the value from the function call? Can someone walk me through it please so I can grasp a better understanding of it.
def square(number):
return number * number
square = (3)
def result(number):
2 Answers
andren
28,558 PointsStoring the result of a function is actually a lot simpler than you might expect, it's pretty much the same as calling it normally expect that you assign the call to a variable. Like so for example:
result = square(3)
That might look like you are storing the function itself in the variable, but Python will execute the function before it performs the assignment, and then assign the value the function returns.
Darrin Spell Jr
Full Stack JavaScript Techdegree Student 10,303 PointsThank you Andren! I actually just figured it out the moment you replied. I went back and watched the video again. In my head I was getting the value (square) mixed up with being a variable within the body of a function but anything in the body is just a value in the function which I can call later within a variable whenever I want to. Is that correct