在 python 中仅从字典中获取一个单词
Get only one word from a dictonary in python
import COVID19Py
covid19 = COVID19Py.COVID19()
latest = covid19.getLatest()
print(latest)
这是我的代码,输出是:
{'confirmed': 106160999, 'deaths': 2317170, 'recovered': 12778299}
但我希望输出类似于:
"There are 106160999 infections and 2317170 deaths and 12778299 recovers"
In [27]: latest = {'confirmed': 106160999, 'deaths': 2317170, 'recovered': 12778299}
In [28]: print(f"There are {latest['confirmed']} infections and {latest['deaths']} deaths and {latest['recovered']} recovers")
There are 106160999 infections and 2317170 deaths and 12778299 recovers
如果你只想访问字典,你可以这样写:
print(f"There are {your_dict["confirmed"]} infections and ....")
您可以像访问数组一样使用键访问字典
import COVID19Py
covid19 = COVID19Py.COVID19()
latest = covid19.getLatest()
print(latest)
这是我的代码,输出是:
{'confirmed': 106160999, 'deaths': 2317170, 'recovered': 12778299}
但我希望输出类似于:
"There are 106160999 infections and 2317170 deaths and 12778299 recovers"
In [27]: latest = {'confirmed': 106160999, 'deaths': 2317170, 'recovered': 12778299}
In [28]: print(f"There are {latest['confirmed']} infections and {latest['deaths']} deaths and {latest['recovered']} recovers")
There are 106160999 infections and 2317170 deaths and 12778299 recovers
如果你只想访问字典,你可以这样写:
print(f"There are {your_dict["confirmed"]} infections and ....")
您可以像访问数组一样使用键访问字典