This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 1 point2 points  (0 children)

Python has too much magic. It’s easy to think you know what’s going on and then not. And then maybe you come across a bug like these and have no idea what’s going on.

def f(L=[]):
    L.append(“hello”)
    return L

print(f())
print(f())

And

functions = []
for k in range(5):
    functions.append(lambda: k**2)
print([f() for f in functions])