WTF Python: Exploring and understanding Python through surprising snippets
1–10 of 169 posts
Re: WTF Python: Exploring and understanding Python through surprising snippets
#2Re: WTF Python: Exploring and understanding Python through surprising snippets
#3Ah, brings to my mind the classic talk: https://www.destroyallsoftware.com/talks/wat
Re: WTF Python: Exploring and understanding Python through surprising snippets
#4Re: WTF Python: Exploring and understanding Python through surprising snippets
#5Re: WTF Python: Exploring and understanding Python through surprising snippets
#6Ah, brings to my mind the classic talk: https://www.destroyallsoftware.com/talks/wat
Edit: okay this thing that gave me a little smile deserved a downvote for some reason I guess. Hope whoever else comes along and doesn’t like a cute fun thing or me enjoying it can explain why.
Re: WTF Python: Exploring and understanding Python through surprising snippets
#7Ah, brings to my mind the classic talk: https://www.destroyallsoftware.com/talks/wat
That one was all cynicism that baited the experienced and confused and discouraged beginners... this one actually takes the important next step of making it all teachable which is really great.
Re: WTF Python: Exploring and understanding Python through surprising snippets
#8Re: WTF Python: Exploring and understanding Python through surprising snippets
#9Ah, brings to my mind the classic talk: https://www.destroyallsoftware.com/talks/wat
I already had the song NaNNaNNaNNaN watman in my head before I clicked the link. Edit: okay this thing that gave me a little smile deserved a downvote for some reason I guess. Hope whoever else comes along and doesn’t like a cute fun thing or me enjoying it can explain why.
Re: WTF Python: Exploring and understanding Python through surprising snippets
#10Ah yes, the one about mutable default arguments was a real surprise for me once in a debugging session. Python only initialising them once during the whole script runtime is not exactly the behaviour anyone would expect.
def main():
funcs = []
for x in range(10)
def f(x=x):
return x
funcs.append(f)
print([f(x) for f in funcs])
The "x=x" default argument is necessary here. In this example it's just a constant but this trick is often used with mutable defaults.