4 ms·
In the Python world, '_' is used in three different ways: * As a throw-away variable: >>> a, b, _, c, d = f(t) * As a gettext call: >>> print _('Wel
by raymondh 12y ago
In the Python world, '_' is used in three different ways:
* As a throw-away variable:
>>> a, b, _, c, d = f(t)
* As a gettext call:
>>> print _('Welcome to Python')
* And at the interactive prompt as the result of the previous expression:
>>> 3 + 4
7
>>> _ * 10
70
- pluma 12y agoAs most of my Python involves localized Django, I twitch every time I see `_` used for anything other than some variation of gettext.
- lazzlazzlazz 12y agoWeird, since the gettext use-case is definitely the least idiomatic and least common use of `_`.
- pluma 12y agoAs I said, most of my Python involves localized Django. So gettext is used everywhere and (apart from the REPL) it's the other uses of `_` that are the odd ones out.
- Walkman 12y agothat's why you should use '__' as throw-away variable (two underscores)
- bobisme 12y agoWow. How did I go years without knowing this about the repl?