Python 如何在给定函数中使用参数v
因此,我能够编写上述代码 现在,我被要求修改do_Twow函数,使其接受两个参数——一个函数对象和一个值,并调用函数两次,以如下格式将值作为参数传递:Python 如何在给定函数中使用参数v,python,function,Python,Function,因此,我能够编写上述代码 现在,我被要求修改do_Twow函数,使其接受两个参数——一个函数对象和一个值,并调用函数两次,以如下格式将值作为参数传递: def do_twice(f): """ This function calls any function object that is passed to it twice """ f() f() def print_spam(): print('spam') do_twice(print_spam) 我无法理解如
def do_twice(f):
"""
This function calls any function object that is passed to it twice
"""
f()
f()
def print_spam():
print('spam')
do_twice(print_spam)
我无法理解如何在函数中使用参数v您需要使函数包含两个参数:
def do_twice(f, v):
"""
This function calls any function object that is passed to it twice passing v as the argument
Input:
f: function object
v: value
"""
### Write your code here
然后可以使用函数和值调用它:
def do_twice(f, v):
例如:
do_twice(some_func, "a string")
您需要使函数接受两个参数:
def do_twice(f, v):
"""
This function calls any function object that is passed to it twice passing v as the argument
Input:
f: function object
v: value
"""
### Write your code here
然后可以使用函数和值调用它:
def do_twice(f, v):
例如:
do_twice(some_func, "a string")
您已经知道如何使用传入参数
f
(直接作为f
),如何调用传入函数(即f()
),以及调用函数时如何传递参数(dou两次(print\u spam)
)。使用传入参数f
和v
时,为了在调用f
时传递v
,您有什么具体问题?您已经知道如何使用传入参数f
(直接作为f
),如何调用传入函数(即f()
)以及调用函数时如何传递参数(do\u两次(print\u spam)
)。使用传入的参数f
和v
,在调用f
时,为了传递v
,您有什么具体问题?