Discuss / Python / 再简单的代码也要亲手敲一遍

再简单的代码也要亲手敲一遍

Topic source

翁岚敏

#1 Created at ... [Delete] [Delete and Lock User]

来一个可变参数,要几个函数就来几个

from math import sqrt def same(x,*fs): s=[f(x) for f in fs] return s print(same(2,sqrt,abs))

创意可以

Henry_Smith

#3 Created at ... [Delete] [Delete and Lock User]

感觉不错。

2012Flyer

#4 Created at ... [Delete] [Delete and Lock User]

支持一个

参数*fs是什么意思啊,还有调用函数时为什么输入是三个参数?

好吧,可变参数

高大上

借鉴了一下

from math import sqrt

def do_sth(x=[],*func):
    return [f(x_k) for x_k in x for f in func]

print(do_sth([1,2,4,9],abs,sqrt))

你们为什么都好厉害啊

ze小Tro

#10 Created at ... [Delete] [Delete and Lock User]

检验了一下,传入函数的参数似乎需要时一样个数的。


Reply