[Django]-What's the meaning of '_' in python?

27👍

Please read up on Internationalization (i18n)

http://docs.djangoproject.com/en/dev/topics/i18n/

The _ is a commonly-used name for the function that translates strings to another language.

http://docs.djangoproject.com/en/dev/topics/i18n/translation/#standard-translation

Also, read all of these related questions on SO:

https://stackoverflow.com/search?q=%5Bdjango%5D+i18n

👤S.Lott

13👍

Not an answer to your case but the more general “What’s the meaning of ‘_’ in python?”:

In interactive mode, a _ will return the last result that wasn’t assigned to a variable

>>> 1 # _ = 1
1
>>> _ # _ = _
1
>>> a = 2
>>> _
1
>>> a # _ = a
2
>>> _ # _ = _
2
>>> list((3,)) # _ = list((3,))
[3]
>>> _ # _ = _
[3]

Not sure, but it seems like every expression that’s not assigned to a variable is actually assigned to _.

👤Nick T

6👍

this is used for gettext function, as is described here

Utf-8 support of django is good, so django handles it as unicodetext as described here

👤Mp0int

0👍

_ indicates last valid output on the screen. System by default stores copy of the output to this _ variable. It does not applies to string that is printed using print function but I stores for the string stored into the variable.

enter image description here

👤Sandip

Leave a comment