When I tried to use a for statement in one line like below,
def get_cubes(x):
ls=[]
ls.append(pow(item*3, 3)) for item in range(int((x-x%3)/3)+1)
return ls
there was always an error:
File "<ipython-input-47-8c391c3d568a>", line 3
ls.append(pow(item*3, 3)) for item in range(int((x-x%3)/3)+1)
^
SyntaxError: invalid syntax
However, it works well when I write it using a standard for loop method. Why?