• Register
0 votes
50 views

I am new to python programming language. I wrote a where I tried to pass a list of functions :

def function(f. *args)
    
    for f in args
    
        print f

I can not pass my list of function using this code It gives me error

  File "main.py", line 1
    def function(f. *args)
                  ^
SyntaxError: invalid syntax

I also tried:

def function(*args)
    for f in args
        print f

But it gives error:

  File "main.py", line 1
    def function(*args)
                      ^
SyntaxError: invalid syntax

How can I solve this and how can I pass a list of function?

10 7 2
6,060 points

Please log in or register to answer this question.

1 Answer

1 vote

Solution:

You need to define named arguments before variable arguments as well as keyword arguments after variable arguments.

You can solve this by writing:

def function(arg1, arg2, arg3, *args, **kwargs)
    for f in args
        print f

Now, this program looks good.

13 9 6
94,240 points

Related questions

0 votes
1 answer 2 views
2 views
Problem: I'm just learning python and confused when a "def" of a function ends? Please answer?
asked 5 days ago Sana8989 8.9k points
0 votes
1 answer 6 views
6 views
Problem: How can I list all the files in a directory in python and add them to a list?
asked Mar 17 sasha 16.2k points
0 votes
1 answer 19 views
19 views
Problem: I am new to python. Can anyone help me out? How to delete a list in python? Thanks!!
asked Mar 5 Samiur1 38.4k points
0 votes
1 answer 6 views
6 views
Problem: How to solve this error: How do I list all files of a directory in python ?
asked Mar 19 Wafa Abu Yousef 6.1k points
0 votes
2 answers 30 views
30 views
How can I list all files of a directory in Python and add them to a list ?
asked Oct 24, 2020 psandprop 2.4k points
1 vote
1 answer 6 views
6 views
Problem: Any clue how to slove this calculation? Multiply all values in a list python.
asked Mar 26 PkGuy 13.1k points
0 votes
1 answer 23 views
23 views
I need to know how to remove duplicate elements from list in python.
asked Oct 5, 2020 Daniel Anderson 4k points
0 votes
1 answer 4 views
4 views
Problem: Hello! I am wondering whether it is possible to append a list to another list in Python or not? What I mean is, suppose I have a list named list1 and have values such as [1,2,3,4,5]. I have another list named list2 having the values [6,7,8,8,9]. Is it possible to append list1 with list2 or vice versa? If yes, how?
asked Mar 24 Code Learner 9.2k points
0 votes
1 answer 4 views
4 views
Problem: how to I Solve this: python add all elements of a list HELP! I need help understanding this: python add all elements of a list Can someone please help solve this, I am new in python(). Someone have idea to solve this thanks!
asked Mar 10 Mashhoodch 13k points
1 vote
1 answer 69 views
69 views
Problem: I am a beginner in programming language and I choose python for this.So I was doing my programming practice. I was looking for a way to convert list to dictionary python. It should applicable. Thank you
asked Apr 2, 2020 LizzyM 6.1k points