这是一组列表代码:
l = [1, 2, 3, 4, 5] def multiply_2(l): for index in range(0, len(l)): l[index] *= 2 return l multiply_2(l)
显然我们可以看到并不是纯函数的形式,我们可以调用生成纯函数内容。
l = [1, 2, 3, 4, 5]、 def multiply_2_pure(l): new_list = [] for item in l: new_list.append(item * 2) return new_list multiply_2_pure(l)