Python Programming Tutorial - 17 - Flexible Number of Arguments

preview_player
Показать описание
Рекомендации по теме
Комментарии
Автор

Just so u know Bucky
Someone's always watching and learning from you even after 6 years....

narayansinghbhadauriya
Автор

If anyone of you is wondering, *args works fine even when different types of arguments are passed within the same function call. For example

def numbers (*args):
for arg in args:
print(arg)

numbers(1, 2, 3) #case1
numbers("alpha", "beta", "gamma") #case2
numbers("one", 2, 3.0) #case3

The output in this case is
#case1
1
2
3
#case2
alpha
beta
gamma
#case3
one
2
3.0

milindbest
Автор

Who ever thought that this looks like passing by reference in C, You are an old school legend now !

mohamedatef
Автор

A function I created using these tutorials to subtract, only thing changed is you have to give a determined starting point for total instead of 0:


def subtract_numbers(first, *args):
total = first
for b in args:
total -= b
print(total)

subtract_numbers(4, 1, 2)


output in this case is 4 minus 1 minus 2 which is 1.

nilacof
Автор

2:00 You have a giraffe in your house?

criskity
Автор

Great videos and much appreciated. Humor and perfect lengths. My kind of style Thx :-)

dannymorckjensen
Автор

def add_numbers(*args):
total=0
for a in args:
total += a
return total



sum=add_numbers(3, 30)
print("result is", sum, )

maliakbulut
Автор

side note: if you choose to multiply rather than add, change the total = 0 to total = 1 (since anything multiplied by 0 is 0 but anything multiplied by 1 is the number itself) and change the += sign to *=

TheSamkhaled
Автор

watching this tutorial exactly at 3:40 AM !!!!:p

satadhi
Автор

celsius to fahrenheit converter by using args

def cel_fahr(*cel):
for x in cel:
fahr=x*9/5+32
print(fahr)

flow
Автор

Hello sir, you are just awesome. You describe the toughest things in a way that anyone can understand. Thank you once again. Sir, is it possible for you demonstrate bully algorithmn in distributes system with python language?

faisal
Автор

first tutorial that i don't really get. can someone please explain line 2

Bilalnwo
Автор

total += a

How does a become the value of the argument, if its only defined in the

for a in args

line?

Like isn't that just like 0 1 2 3 4 5 for each time it's called?

piattrocks
Автор

"...the ashcherishk sign."   Hahaha.  When pronouncing asterisk, think "master of risk".  Now remove the 'of'.  Master risk.  Now remove the 'M' and you got it.  Aster-risk.  Asterisk.

greatsea
Автор

omg an '*'! Can it be a pointer, please let it be so, I love pointers! Coming from c++ this language seems so odd to me atm, keep trying to put a damn semi-colon at the end of every line. I am seriously hoping for pointers though.

dabooda
Автор

Mean calculator

def average(*args):
mean = 0
len1 = len(args)
for a in args:
mean += a/len1
print(mean)

ninipopo
Автор

how to declare datatype or variable type in the program why are you not making user defined program

yogitamodi
Автор

+thenewboston hey bucky if i type in this code i could add the numbers but the numbers keep pooping in each time i add an anothe number for example if i want to add add 3 and 5 it would show me the output as 3 and 8 pls help me in this regard
def explaining_arguments(*args):
car = 0
for e in args:
car +=e
print(car)
explaining_arguments(3, 5)

output:3
8

srineeshsalur
Автор

Ok, so if you set 'for n in range' to 1001, with the 'magic number' value set to 256 (or less) the program works fine. As soon as you increase it to 257 (or more) it immediately fails.  Why??

supadupahilton
Автор

How would you make a list the argument for a function to be a list, x = [ 1, 2, 3, 4, 5, 6, ] and i want to add all six up?
Thanks a lot

sansamman