3 ms·
> The underscore _ can be used as a throwaway variable to discard unwanted values: So can any other variable, using underscore is just a convention to make it
by aorist 3y ago
> The underscore _ can be used as a throwaway variable to discard unwanted values:
So can any other variable, using underscore is just a convention to make it obvious that you're not planning to re-use it (it doesn't get GCed more aggressively or anything).
Similarly, private methods being prefixed with an underscore is also just a convention, you can access them from anywhere.
However, double underscores are used for magic attributes and name mangling for class attributes, which are interpreted differently! (See: https://stackoverflow.com/a/1301369 https://stackoverflow.com/a/1301369)
- noitpmeder 3y agoMany linters are also configured to ignore '_' for many tests (such as any 'unused variable' warnings)
- Fatnino 3y agoIn the interactive environment _ automatically holds the value of the last statement executed. >>> 1+1 2 >>> _ * 3 6