0
Return sum of numbers from a function python
Ex your_function(1, 5, -3, âabcâ, [12, 56, âcadâ]) will return 3 (1 + 5 - 3) So how can I get the func to return the sum of the digits ? And if the func is empty your_function() it will return 0
3 RĂ©ponses
0
here is my try
def only_number_sum(mixed_list):
num_list = []
for mixed in mixed_list:
if type(mixed) in [type(1) , type(1.0)]:
num_list.append(mixed)
return sum(num_list)
0
works perfectly thx man!
0
you can use the method isdigit for all your parameters.
for example:
def func_sum(*par):
s=0
for e in par:
if str(e).isdigit():
s+=e
return s