
Hi Julia, and welcome! On Wed, Jun 02, 2021 at 05:16:29AM +0200, Julia Schmidt wrote:
The wildcard idea looks just wrong and confusing. What if I want to use it as a variable and match against it like _ = 504?
Don't do that. There is a very strong convention in Python that a single underscore is to be used for two purposes (and a third in the interactive interpreter only): (1) For "don't care" variables; anything that you don't care about and aren't intending to use should be named `_`. first, *_, last = sequence This tells me that I am only using the first and last items, everything else is ignored. (2) For internationalisation. This is a convention that comes from other languages, but it is so widespread that we're kinda stuck with it. print(_("Try again.")) By convention, the underscore function is used to translate messages into the current location's language. (3) And in the interactive interpreter, underscore is a special variable which captures the previous result. This doesn't work in scripts. >>> 5 + 4 9 >>> _*10 90 So aside from localisation, the Pythonic convention is that a name consisting only of an underscore alone is something to be ignored. There is no shortage of names. (However, good, informative, self- descriptive names are harder to come by.) If you really must name something with an underscore, instead of giving it an informative name, you can just use two underscores. Three or more would be better, to make it more visually distinctive. ____ = 504 # Why not HTTP_GATEWAY_TIMEOUT ??? But for what it's worth, if I were doing a code review and saw somebody using underscore-only names for anything but "ignore this", I would likely be asking some pointed questions about why it was using such obfuscated names. -- Steve