In this example, the square()
function takes a parameter x
and returns the square of x
. We call the function with x=3
, and store the returned value in the variable result
. We then print the value of result
, which should be 9
.
The syntax of a simple square()
function in Python would look like this:
How to square numbers in Python? | Python Tutorial – Flexiple
def square(x):
"""This function returns the square of the input"""
return x ** 2
Basic Function Example
Python Projects Topic to build in Your Project
def square(x):
"""This function returns the square of the input"""
return x * x
# Call the function
result = square(3)
print(result)
Output
9