Every story and comment from the Hacker News API, in a layout borrowed from 2001.
A comment on WTFPython: Exploring and understanding Python through surprising snippets. Parent comment
In both cases, "foo" continues to exist after the "if" even though the second example makes it look like "foo" is scoped to the "if".
So to my eye, the following would look super weird (assume do_more_stuff can take None):
if foo := one_or_none(): do_stuff(foo) do_more_stuff(foo)
foo = one_or_none() if foo: do_stuff(foo) do_more_stuff(foo)
There are no comments on this comment yet.
In both cases, "foo" continues to exist after the "if" even though the second example makes it look like "foo" is scoped to the "if".
So to my eye, the following would look super weird (assume do_more_stuff can take None):
whereas the following would look fine: