• Register
0 votes
42 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
2 answers 20 views
20 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
0 votes
1 answer 14 views
14 views
I need to know how to remove duplicate elements from list in python.
asked Oct 5, 2020 Daniel Anderson 4k points
1 vote
1 answer 49 views
49 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
0 votes
1 answer 49 views
49 views
Problem Hi Kodlogs, How do I list all files in a directory and its subdirectories in Python? Apparently, I am unable to do so.
asked Oct 28, 2020 hashq 1.1k points
0 votes
1 answer 4 views
4 views
Problem: I have a list of arbitrary length and I need to split it into chunks of the same size and process it. There are some obvious ways to do this, like keeping a counter and two lists, and when the second list is full, add it to the first ... of any length, for example using generators. I've searched for something useful in itertoolsbut couldn't find anything useful. I may have missed this.
asked Dec 23, 2020 sasha 5.3k points
0 votes
1 answer 17 views
17 views
Please explain with some examples?
asked Nov 5, 2020 jagruthi 680 points
1 vote
1 answer 200 views
200 views
Problem: I have been doing programming for a while and I am using python for this. So my question is What is an advantage of using a tuple rather than a list? Thank you
asked Apr 6, 2020 LizzyM 6.1k points
0 votes
1 answer 21 views
21 views
How do I loop over python list with variables ?
asked Oct 28, 2020 psandprop 2.4k points
1 vote
2 answers 57 views
57 views
Problem: I am new to programming language. I was trying to find common elements in two lists using python. So I wrote this code: a = [1, 2, 6, 9] b = [1, 3, 8, 9] a_as_set = set(b) intersection =a_as_set.intersection(b) intersection_as_list = list(intersection) print(intersection_as_list) This code gives me the output: [8, 1, 3, 9] Which is not right. Please help me to get the exact output.
asked Mar 28, 2020 LizzyM 6.1k points
1 vote
1 answer 1.2K views
1.2K views
Problem: I am a beginner in python programming language. I tried to create a program to calculate my students avarage results so I wrote this code porter = { "name": "Porter", "homework": [90.0, 97.0, 75.0, 92.0], "quizzes": [88.0, 40.0, 94.0] ... try again. getclassaverage([porter]) resulted in an error: 'list' object attribute 'append' is read-only" Can anyone help me out to solve this problem?
asked Apr 5, 2020 LizzyM 6.1k points