我在读一本Python书中的练习,内容如下:
修改do\u两次,使其接受两个参数,一个函数对象和一个值,并调用函数两次,将值作为参数传递。在
编写一个更通用的print_spam版本,称为print_tween,它以一个字符串作为参数并打印两次。在
使用修改后的do峎ou两次调用print峎两次,并将“spam”作为参数传递。在
我写的是:
def do_twice(f, g):
f(g)
f(g)
def print_spam(s):
print (s)
do_twice(print_spam('lol'))
它应该怎么写?我在这件事上完全被难住了。在
如果出于某种原因你想重复n次函数,你也可以写类似这样的东西。。。在
只需将}作为参数:
string
作为do_twice
的第二个参数。do_twice
函数调用print_spam
,并提供{印刷品:
^{pr2}$相关问题 更多 >
编程相关推荐