Live data from Hacker News

WTF Python: Exploring and understanding Python through surprising snippets

github.com

1–10 of 169 posts

Re: WTF Python: Exploring and understanding Python through surprising snippets

#3
post #2

Ah, 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

#6
post #2

Ah, 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

#7
post #3
post #2

Ah, 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.

Oh come on Gary literally runs a top notch teaching site and the link was a bit of fun on his previous teaching site.

Re: WTF Python: Exploring and understanding Python through surprising snippets

#9
post #2

Ah, 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.

You do know what they say about Watman - he's not the hero we deserved but the hero we need. Have a nice day!

Re: WTF Python: Exploring and understanding Python through surprising snippets

#10

Ah 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.

They're also an escape hatch,

    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.
Post reply on HN