Python newbie here.I wrote this function to only return even numbers as a list but I am failing at doing this. Can you please help? This is my initial function which works fine but results are not coming out as a list:
def myfunc (*args):
for num in args:
if num % 2 == 0:
print (num)
When you call the function for example with the following arguments:
myfunc(1,2,3,4,5,6,7,8,9,10)
I am getting:
2
4
6
8
10
but I need those to be in a list, what am I missing? This doesn't work either:
list = []
def myfunc (*args):
for num in args:
if num % 2 == 0:
print (list[num])
Much appreciated!