Python function

Function example 1Python logo

Function that adds two numbers entered per parameter

def my_sum(n1, n2): 
    total = n1 + n2 
    print (total)

my_sum(1,2)

3

 

Function example 2

Function that returns two numbers passed as a list

def my_sum(n1, n2):
return n1 + n2

data = [1, 2]
print (my_sum(*data))

 

Function example 3

Function that returns two numbers passed as a dictionary

def my_sum(n1, n2): 
    return n1 + n2
 
diccionary = {"n1": 1, "n2": 2} 
print (my_sum(**diccionary))