0

I recently started working on python and have seen a lot of _ being used. I understand that _ is used to ignore values for e.g.

name, _ , shape = get_fruit() # returns a tuple. 

However, I couldn't get many articles on _ functions e.g.

from django.utils.translation import gettext as _

Why is _ used here instead of simply using gettext() ?

Manju Prabhu
  • 454
  • 6
  • 14
  • 2
    Duplicate of https://stackoverflow.com/questions/5893163/what-is-the-purpose-of-the-single-underscore-variable-in-python – Subhrajyoti Das Aug 21 '19 at 04:29
  • 1
    It's important to understand, `_` is just a normal variable name, like `x` or `foo`. Conventionally, it's reserved for variables that aren't going to be used, as a *signal to the person reading the source code*, but it has no special status in Python. – juanpa.arrivillaga Aug 21 '19 at 05:02
  • It's used for `gettext` to be less obtrusive. It works without interrupting the visual flow of the code. – hpaulj Aug 21 '19 at 05:31

0 Answers0