Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the underscore represent in Python?

Tags:

python

I am kind of new to Python, so I am trying to read over existing code. I am a little confused on the syntax of this though.

For example:

rlist, _, _ = select.select(sockets, [], [])

I understand that select.select() takes 3 lists (and I assume [] just means empty list), but is the _ used to denote a placeholder of some sort?

like image 663
Thomas T Avatar asked Sep 21 '12 23:09

Thomas T


1 Answers

It's just the name of a variable! Usually people use _ for variables that are temporary or insignificant.

As other people have stated, _ is a common alias for gettext, a translation library. You can identify when it's being used as gettext if you see it called as a function, eg. _('Hello, world!').

Protip: In the python console it can be used to retrieve the result of the last statement.

>>> 3 + 4
7
>>> a = _
>>> print a
7
like image 132
Thane Brimhall Avatar answered Sep 28 '22 09:09

Thane Brimhall