Python字典如何换行
Python字典换行的方法如下:
1、换行时保证行尾是逗号即可
a={"key0":"val0", "key1":"val1", "key2":"val2"}
2、在长度不影响阅读的情况下这种写法也是允许的:
a={"key0":"val0","key1":"val1", "key2":"val2","key3":"val3", "key4":"val4","key5":"val5"}
注意这种情况下,每一行第一个非空白字符都要和第一行的括号后的字符对齐,并且最后的括号是不换行(直接跟在最后一个元素后面)的。
3、另外一种换行方法如下:
a={ "key0":"val0", "key1":"val1", "key2":"val2" } a={ "key0":"val0", "key1":"val1", "key2":"val2" }
或是
a={ "key0":"val0","key1":"val1", "key2":"val2","key3":"val3", "key4":"val4","key5":"val5" } a={ "key0":"val0","key1":"val1", "key2":"val2","key3":"val3", "key4":"val4","key5":"val5" }
这种情况下,内容的每一行都需要比第一行只多一层缩进(即4个空格)
原文来自:https://www.py.cn© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END
暂无评论内容