![](/img/trans.png)
[英]Why does this python dictionary get created out of order using setdefault()?
[英]Why does using setdefault on a dictionary in python print it out?
I'm on Windows, using the PyCharm IDE's terminal to ssh into a linux server, on that server I'm using python interactively. 當我用值更新字典時,終端將值輸出回給我:
>>> x={}
>>> x.setdefault("y",0)
0
我無法弄清楚為什么會這樣。 我以前從未注意到這種行為? 我還嘗試使用 Windows 10 終端直接對 ssh 進行 ssh,但同樣的事情發生了,所以它不是 PyCharm 特定的。
我只是不希望每次我嘗試設置字典時它的視覺混亂都會給我一個價值。 是什么讓它做到這一點? 這是我第一次通過 Windows 登錄所以我覺得這在某種程度上是罪魁禍首?
它不是 windows 特定的。“setdefault”返回鍵的值,您也在交互模式下使用 python,您將獲得返回值。 您可以將其分配給變量。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.