---
title: "Comment by Nickolai Belakovski on \"Python Gotchas: 5 Worst Mistakes You Should Avoid\" | Hashnode"
description: "Great article. I think the example for the walrus operator could be better. Something like # We want to increment by the number if it&#x27;s nonzero, otherwise"
url: "https://hashnode.com/posts/python-gotchas/5f93f46afbdce372c9a56d6b/comment/5f9487f440346172a86c1dcc"
---

[Discussion](https://hashnode.com/posts/python-gotchas/5f93f46afbdce372c9a56d6b)

Comment [Python Gotchas: 5 Worst Mistakes You Should Avoid](https://hashnode.com/posts/python-gotchas/5f93f46afbdce372c9a56d6b)

[Nickolai Belakovski](https://hashnode.com/@actinium226)

[Oct 24, 2020](https://hashnode.com/posts/python-gotchas/5f93f46afbdce372c9a56d6b/comment/5f9487f440346172a86c1dcc)

Great article.

I think the example for the walrus operator could be better. Something like

```
# We want to increment by the number if it's nonzero, otherwise we want to increment by at least 1
x = get_some_number_maybe_0()
if x:
  y += x
else:
  y += 1
```

Which can be transformed with walrus operator to:

```
if x := get_some_number_maybe_0():
    y += x
else:
    y += 1
```

If the example you've shown, `should_run` isn't necessary, you can just base the if statement on the return of the os.environ call.

I guess the above could also be done as y += max(1, get\_some\_number\_maybe\_0()). Dammit, I need to stop finding ways to optimize my examples :P

Edit: The PEP introducing the operator has some better, albeit more complicated examples [python.org/dev/peps/pep-0572](https://www.python.org/dev/peps/pep-0572/#syntax-and-semantics)

[Miguel Brito](https://hashnode.com/@miguendes)

[Oct 25, 2020](https://hashnode.com/posts/python-gotchas/5f93f46afbdce372c9a56d6b/comment/5f9487f440346172a86c1dcc#reply-5f952f6040346172a86c22df)

Thanks for the feedback [Nickolai Belakovski](https://hashnode.com/@actinium226). I've updated the post to make it clearer.
