• Register
0 votes
38 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,050 points

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
0 answers 3 views
3 views
How can I list all files of a directory in Python and add them to a list ?
asked 16 hours ago psandprop 800 points
0 votes
1 answer 7 views
7 views
I need to know how to remove duplicate elements from list in python.
asked Oct 5 Daniel Anderson 4k points
1 vote
1 answer 40 views
40 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 LizzyM 6.1k points
1 vote
1 answer 72 views
72 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 LizzyM 6.1k points
1 vote
2 answers 48 views
48 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 LizzyM 6.1k points