Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the name of this operator “ _ ” in Python?

Tags:

python

I was reading Hidden features of Python and I came across this answer.

Right from the post:

When using the interactive shell, "_" contains the value of the last printed item:

>>> range(10)
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> _
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>>

What is the name of this operator ? I cannot find it on the document and I've never heard of it (as well as in other languages). Is it worth using it?

PS. I want to know its name because I want to see how the function is implemented and to search if other languages have this awesome function.

like image 837
Thanakron Tandavas Avatar asked Apr 07 '13 20:04

Thanakron Tandavas


People also ask

What does |= mean in Python?

|= on Booleans The Python |= operator when applied to two Boolean values A and B performs the logical OR operation A | B and assigns the result to the first operand A . As a result, operand A is False if both A and B are False and True otherwise. What is this?

Is <> An operator in Python?

The <> operator has been removed from Python 3. ...and <> isn't mentioned in the v3 documentation at all. @ T.J. Crowder: Thanks for the clarification about the 2.

What is operator Itemgetter in Python?

itemgetter (item) operator. itemgetter (*items) Return a callable object that fetches item from its operand using the operand's __getitem__() method. If multiple items are specified, returns a tuple of lookup values.


1 Answers

It's neither an operator nor a function. It's a variable that automatically gets assigned the result of each expression executed by the shell.

like image 124
NPE Avatar answered Oct 21 '22 19:10

NPE