How to Make a Function in Python
- Jul 10, 2024
- 1 min read
The keyword for declaring a new function is def, short for define
def function_name(x,x):
return (x,x)
example:
def is the key word for declaring a new function
SumOfTwoIntegers() is the name of our function
Fnum and Snum are the inputs of our functions. We want the user to provide Fnum and Snum (two inputs)
sum = Fnum + Snum -> this is the thing the function does. the function makes a sum variable by addint the two inputs
return is the keyword for making the function give an output
How to Use the Function:
in this example, we put our two inputs as x and y (15 and 20)
it then took the sumoftwointegers function and computed the sum with the two inputs we gave it. it then returned the sum (35).




Comments