Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

_.startswith() overides the variable _

Tags:

python-3.x

Is the behaviour described below by purpose (Python 3.7) ?

_ = '==TEST=='
_.startswith('==')
Out[29]: True
_
Out[30]: True

l = '==TEST=='
l.startswith('==')
Out[26]: True
l
Out[27]: '==TEST=='

I know the variable names are a poor choice but why does the call to .startswith override the variable _ ?

like image 457
Moritz Avatar asked Mar 19 '26 08:03

Moritz


1 Answers

When you run python in interactive mode it stores the value of each expression you evaluate into the underscore variable.

like image 162
Lawrence D'Anna Avatar answered Mar 21 '26 23:03

Lawrence D'Anna



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!