Python Python Basics Functions and Looping Create a Function

Umoja Phiri
Umoja Phiri
462 Points

How do I call my call my function

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

result = square("number")

print(result)

2 Answers

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 82,446 Points

Instead of the print() method you just need to call the function by specifying its name, followed by curly braces. Then you pass in the value that the function is expecting.

Remember when you declared the function like this def square(number): You passed in a variable which you used an argument for the function. number.

As you see the function returns the result of a calculation. All you have to do is provide the number and that is what happens in a function call.

square(5);
Umoja Phiri
Umoja Phiri
462 Points

Perfect. You're awesome Jonathan