3

How to send each list element as a function parameter in python?

list1 = ['38', '39', '40', ...]
any_function(list_item)

I can't know that length of the list that's why i can't send every element of the list as a function's parameter at the same time. Is there any Pythonic way?

Telomeraz
  • 43
  • 5
  • https://stackoverflow.com/questions/36901/what-does-double-star-asterisk-and-star-asterisk-do-for-parameters – Chris Jun 08 '20 at 17:26

2 Answers2

2

Change your function parameter to e.g. *args:

list1 = ['38', '39', '40']

def printemall(*args):
    print(args)

printemall(list1)
# (['38', '39', '40'],)

printemall(*list1)
# ('38', '39', '40')
Jan
  • 42,290
  • 8
  • 54
  • 79
0
def any_function(item):
    print(item)

def calling_function():
    list1 = ['38','39', '40']
    for item in list1:
        any_function(item)
Mavice
  • 1
  • 1
  • While this code may answer the question, providing additional context regarding why and/or how this code answers the question improves its long-term value. – Nic3500 Jun 09 '20 at 05:02
  • No, that's not the answer i want.What i want is passing each element of a list at the same time. – Telomeraz Jun 10 '20 at 06:22