-2

I'm on Windows, using the PyCharm IDE's terminal to ssh into a linux server, on that server I'm using python interactively. When I update a dictionary with a value, the terminal outputs the value back to me:

>>> x={}
>>> x.setdefault("y",0)
0

I can't figure out why this is happening. I've never noticed that behavior before? I also tried to ssh directly with the Windows 10 terminal but the same thing happens, so it's not PyCharm specific.

I just don't want the visual clutter of it throwing a value back at me every time I try to set up a dictionary. What could be making it do this? It's the first time I login through Windows so I feel like this is somehow the culprit?

Thymine
  • 99
  • 2

2 Answers2

0

It's not windows specific."setdefault" returns the value of key also you are using python in interactive mode you will get the returned value. you can assign it to variable.

Poonam Adhav
  • 382
  • 3
  • 10
0

Thymine!

This is the expected behavior, as you can see in the documentation

setdefault(key[, default])

If key is in the dictionary, return its value. If not, insert key with a value of default and return default. default defaults to None.

Maybe this can help you too