Python function

by | Jul 15, 2017 | Python-example | 0 comments

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))

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *