Python *args 📦

preview_player
Показать описание
Python *args tutorial example explained

#python #args #tutorial

# *args = parameter that will pack all arguments into a tuple
# useful so that a function can accept a varying amount of arguments

def add(*args):
sum = 0
for i in args:
sum += i
return sum

print(add(1,2,3,4,5,6,7,8))

––––––––––––––––––––––––––––––
Creative Commons — Attribution-ShareAlike 3.0 Unported— CC BY-SA 3.0
––––––––––––––––––––––––––––––
Рекомендации по теме
Комментарии
Автор

# *args = parameter that will pack all arguments into a tuple
# useful so that a function can accept a varying amount of arguments

def add(*args):
sum = 0
for i in args:
sum += i
return sum


print(add(1, 2, 3, 4, 5, 6, 7, 8))

BroCodez
Автор

I did not really understand this one, so i thought i'd share my findings,
for the function add, he puts sum=0 at the start for the sum += i later on
sum += i is another way to put sum=sum+i, since sum was defined as 0 earlier on, this will allow 0 to add to all of the tuple values, and the result being assigned the key of sum.
Hope this helps the fellow first time/newbie coders such as me :))

onlyLewds
Автор

U will reach 1M subs quickly. You provide so much value to the platform and really thank you for that

panagiotisbotonakis
Автор

Very useful video tutorial - thank you

luthfahood
Автор

your style is awesome and very understandable thanks for the good work Bro....

njavamonkb
Автор

That's very usefull. Very nice video.

rebootlinux
Автор

Thanks for explaining WHY you would do this!!

thedevbek
Автор

I love you Bro, sending lots of good vibes your way.

katsowkat
Автор

Thanks for this tutorials really helpful

AnishSaha_
Автор

If channel was a song it would be "It was a good day" by Ice Cube, keep up the great work

elliotradley
Автор

Man ur a legend that happen once in a millenium
Thanks :)

Shinji_ikari_
Автор

what's if for subtraction? im very dizzy now

zdplpr
Автор

i didn't understand the list method why the answer is 20 it should be 21 please anyone help me

StrangerDanger