To create a function that adds two numbers in Python, you can define a function with two parameters and return the sum of the two parameters:
main.py52 chars3 lines
You can then call this function and pass in two numbers as arguments:
main.py55 chars3 lines
In this example, the add_numbers
function takes two parameters num1
and num2
, and returns the result of adding them together with the +
operator. When the function is called with the arguments 2
and 3
, the result 5
is returned and stored in the variable result
, which is then printed to the console.
gistlibby LogSnag