如何解释列表理解表达式不起作用(python 3.8.2 32bit env):
def perfect_squares(max_psqare):
psqares = [0]
return [psqares.append(psqares[-1] + 2 * i - 1) for i in range(1, int(max_psqare ** 0.5) + 1)]
对比:
def perfect_squares(max_psqare):
psqares = [0]
max_base = int(max_psqare ** 0.5)
for i in range(1, max_base + 1):
psqares.append(psqares[-1] + 2 * i - 1)
return psqares
第一个给出 None 值的数组?理解表达式无权访问 psqares 堆栈?