Python 3.4 - Unpacking Arguments

Unpacking a list of arguments can be laborious. But by using the unpacking feature you may let the program do it for you. As seen below, both of the functions call on the data, the unpacked on does it for you, whereas the previous one is coded by hand to call on each argument. 

def health_cal(age, apples, cigs):
    answer = (100-age) + (apples *3) - (cigs * 2)
    print(answer)

my_data = [38, 2, 2]

health_cal(my_data[0], my_data[1], my_data[2])

health_cal(*my_data)


https://www.geeksforgeeks.org/packing-and-unpacking-arguments-in-python/

https://www.youtube.com/watch?v=DJ2HSCT6Z8w

Comments

Popular posts from this blog

Pyhton 3.4 - Continue

Conversations Ongoing: Valuing Modernization in Early European History

Conversations Ongoing: A Bunch of Amateurs