Underscore _ as variable name in Python [duplicate]

Yep, _ is a traditional name for “don’t care” (which unfortunately clashes with its use in I18N, but that’s a separate issue;-). BTW, in today’s Python, instead of: _,s = min( (len( values[s]), s) for s in squares if len(values[s]) > 1 ) you might code s = min((s for s in squares if len(values[s])>1), … Read more

What is the purpose of the single underscore “_” variable in Python?

_ has 3 main conventional uses in Python: To hold the result of the last executed expression in an interactive interpreter session (see docs). This precedent was set by the standard CPython interpreter, and other interpreters have followed suit For translation lookup in i18n (see the gettext documentation for example), as in code like raise … Read more