get函数的使用
来源:4-4 实操实现:天气预报功能
慕容3582308
2020-06-29 07:11:27
get函数,可以为不存在的key设置默认值,这里天气 输出的, . get(ciyt) 是什么意思。?get函数,还有其他用法么?
werat_caty【werat["name"]】=werat 这是怎么一个,用法,我怎么感觉前边没有学习过呢?
1回答
好帮手慕笑蓉
2020-06-29
同学,你好。
1、get() 是根据 key 得到 value 值,以得到北京的天气为例:weather_data.get(city)中的city变量值是北京,即:weather_data.get("北京"),得到的即是key为北京的values是北京天气的值:

2、以北京为例:weather_data[weather["name"]] = weather中的weather["name"]是得到weather的key为name的值“北京”,将得到的值放到weather_data中,且赋值,如:

如果解决了你的疑惑,请采纳,祝学习愉快~
相似问题