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

28th Jan 2022, 6:54 AM
Ticoan Ionut
Ticoan Ionut - avatar
3 ответов
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)
28th Jan 2022, 7:13 AM
hamishhr
hamishhr - avatar
0
works perfectly thx man!
28th Jan 2022, 8:41 AM
Ticoan Ionut
Ticoan Ionut - avatar
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
28th Jan 2022, 8:53 AM
YoPycode