In Python _ has 3 main conventional uses:
The first one is it holds the result of the last executed expressions or statements in an interactive interpreter session. This pattern was set by the standard CPython interpreter, and other interpreters have followed suit.
It is also used for translation lookup in i18n(internationalization), the code looks like as follows:
raise forms.ValidationError(_("Please enter a correct username"))raise forms.ValidationError(_("Please enter a correct username"))
The third and most important use of _ is, it is a general purpose "throwaway" variable name to indicate that part of a function result is being deliberately ignored (Conceptually, it is being discarded.), as in code like:-
label, has_label, _ = text.partition(':')
The last two purposes can conflict, so it is necessary to avoid using _ as a throwaway variable in any code block that also uses it for i18n translation.