簡體   English   中英

{}、“”和:python3 的剝離字典

[英]strip dictionary of {}, “” and : python3

我想知道如何剝離字典

>>> dict = {"hello", "world"}
>>> print(dict)
{"hello" : "world", "hi" : "StackOverflow"}

我該怎么做 output

hello world
hi StackOverflow

嘗試這個:

my_dict = {"hello" : "world", "hi" : "StackOverflow"}

for i, j in my_dict.items():
    print(i, j)

Output:

hello world
hi StackOverflow

遍歷dict.items()並根據您想要的格式打印。

for k,v in dict.items():
   print("{} {}".format(k,v))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM