Python 自学小知识留存

1.Python format 格式化函数,format 函数可以接受不限个参数,位置可以不按顺序。

简单举例:更多参考http://www.runoob.com/python/att-string-format.html

Python 自学小知识留存

2.Python 字典(Dictionary) keys()方法,用dict.keys()方法返回一个字典dict的所有键。

test = {
    "statusCode": 200,
    "data": {
        "totoal": "5",
        "height": "5.97",
        "weight": "10.30",
        "age": "11"
    },
    "msg": "成功"
}
def get_keyvalue(data):
    for key in data.keys():
        key_value = data.get(key)
        if isinstance(key_value, dict):
            get_keyvalue(key_value)
        else:
            print('key='+str(key)+'  '+'value='+str(key_value))

print('直接使用data.keys()方法取出key'+str(test.keys()))
print('使用递归循环取出data.keys')

Python 自学小知识留存