Comment on My Rust experience after eight yearsparentComments−singhrac1yEh, I write a lot of Python and while it's unnecessary, it can make code easier to read if not overused. if (config_fn := base_dir / "config").exists(): ... is just a tiny bit shorter than this: config_fn = base_dir / "config" if config_fn.exists(): ... but if you do this enough times (if you are handling a lot of possible errors / missing data, etc.) it can definitely shorten the code.−jessekv1yIf you have to wrap it in parens, it might be shorter but it's not really clearer.In other contexts, parens are a good indication it's time for a new line.But I can agree something like this does look clean and clear: if value := obj.get("key"): ...
Comments
Eh, I write a lot of Python and while it's unnecessary, it can make code easier to read if not overused.
is just a tiny bit shorter than this: but if you do this enough times (if you are handling a lot of possible errors / missing data, etc.) it can definitely shorten the code.If you have to wrap it in parens, it might be shorter but it's not really clearer.
In other contexts, parens are a good indication it's time for a new line.
But I can agree something like this does look clean and clear: