Python Python Basics Functions and Looping Create a Function

Darrin Spell Jr
Darrin Spell Jr
Python Web Development Techdegree Student 2,316 Points

How 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.

squaring.py
def square(number):
    return number * number

square = (3)

def result(number):

2 Answers

andren
MOD
andren
Treehouse Moderator 28,076 Points

Storing 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
Darrin Spell Jr
Python Web Development Techdegree Student 2,316 Points

Thank 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