Python编程好习惯(持续补充)

1、字典 dict 类型的初始化赋值

refer to:https://stackoverflow.com/questions/8406242/why-does-pycharms-inspector-complain-about-d

my_dict = {}
my_dict['key1'] = 'value1'
my_dict['key2'] = 2

dict 初始化应尽量写在一个语句里。list 也如此,只要是明确包含的元素,都应当在初始化阶段写在变量定义里面。

my_dict = {'key1': 'value1'
           'key2': 2}
posted @ 2018-08-07 16:02  RickyShilx  阅读(368)  评论(0编辑  收藏  举报