• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: Underscore variable with walrus operator in Python

Resolved: Underscore variable with walrus operator in Python

0
By Isaac Tonny on 17/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

In Python, the variable name _ (underscore) is often used for throwaway variables (variables that will never be used, hence do not need a proper name).
With the walrus operator, :=, I see the need for a variable that is rather short lived (used in say only one line of code). I wonder if the use of _ is reasonable to use also in this case, or if it might be confusing for someone reading the code?
Example:
Here a pandas series is created and immediately filtered. The name dummy could in my opinion be replaced with _:

Answer:

You are using the variable dummy, to filter the series. Therefore, don’t replace it with _.

If you have better answer, please add a comment about this, thank you!

dummy-variable python walrus-operator
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: Java Virtual Machines deleted

27/03/2023

Resolved: PyCharm cannot see my newly compiled .pyc see on import

27/03/2023

Resolved: I am facing ERR_HTTP2_PROTOCOL_ERROR on my website

27/03/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.