Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does python have Matlab's `ans` variable that captures returned value not stored in any variable?

Tags:

python

matlab

If you are familiar with Matlab, there is a global variable ans that captures the first return value of a function that is not assigned to any particular variable. Is there any matching construct in Python?

like image 558
erogol Avatar asked Nov 04 '13 00:11

erogol


People also ask

What does ANS mean in Python?

"Least Astonishment" and the Mutable Default Argument. 709. 3588. 2115.

Which is faster Python or Matlab?

Matlab is faster than Python, but Python is better at running multiple jobs in parallel.


1 Answers

You’re looking for _:

>>> 1+1
2
>>> _
2
>>> def f(x): 
...     return x+1
... 
>>> f(3)
4
>>> _
4
like image 191
inspectorG4dget Avatar answered Sep 23 '22 15:09

inspectorG4dget