Python编码风格的空间 [英] Spaces in Python coding style

查看:143
本文介绍了Python编码风格的空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Python教程中提到在运算符周围使用空格,逗号后面使用空格,但不能直接在括号结构中使用:a = f(1,2)+ g(3,4)。什么是不直接在包围结构内是什么意思? 可能来自 PEP 8 - Python代码样式指南。具体来说,请参阅在表达式和语句中使用空格一节。



从这一部分:

 在以下情况下避免无关的空格:

- 立即在括号,括号或大括号内。
$ b是垃圾邮件(ham [1],{eggs:2})
否:垃圾邮件(ham [1],{eggs:2})


Python tutorial says "Use spaces around operators and after commas, but not directly inside bracketing constructs: a = f(1, 2) + g(3, 4)." What does "not directly inside bracketing constructs" exactly mean?

解决方案

That probably comes from PEP 8 -- Style Guide for Python Code. Specifically, see the section on "Whitespace in Expressions and Statements."

From that section:

Avoid extraneous whitespace in the following situations:

- Immediately inside parentheses, brackets or braces.

  Yes: spam(ham[1], {eggs: 2})
  No:  spam( ham[ 1 ], { eggs: 2 } )

这篇关于Python编码风格的空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆