Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does the Python repl print different things for None? [closed]

Today I was playing with a Python dict and I found something weird:

>>> print {}.get('non-existant-key')

>>> a = {}.get('non-existant-key')
>>> print a
None
>>>

Why does the repl print an empty space with the first print and "None" after taking the step of storing the value in the variable a? The thing it tries to print is the same in both cases, so why is there be a difference?

like image 276
kramer65 Avatar asked Mar 09 '26 00:03

kramer65


1 Answers

Okay, turns out it wasn't the behaviour of the Python repl, but the (for the rest excellent) bpython repl which I always use. I didn't realise I was using bpython instead of the vanilla python when I was testing this.

In the regular pyton repl it all works as expected. I'll file a bug with bpython about this.

like image 113
kramer65 Avatar answered Mar 10 '26 15:03

kramer65



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!