我正在编写一个对列表中的每个元素进行平方的函数。
def square(num):
for i in range(len(num)):
square[i] = square[i] ** 2
def action():
nums = [2, 3, 4]
print square(nums)
action()
它返回一个错误:
square[i] = square[i] ** 2
TypeError: 'function' object has no attribute `__getitem__`.
想法?