When is semicolon use in Python considered “good” or “acceptable”?

后端 未结 2 1701
孤独总比滥情好
孤独总比滥情好 2020-12-03 03:04

Python is a \"whitespace delimited\" language. However, the use of semicolons are allowed. For example, the following works but is frowned upon:

p         


        
2条回答
  •  悲哀的现实
    2020-12-03 03:15

    PEP 8 is the official style guide and says:

    Compound statements (multiple statements on the same line) are generally discouraged.

    (See also the examples just after this in the PEP.)

    While I don't agree with everything PEP 8 says, if you're looking for an authoritative source, that's it. You should use multi-statement lines only as a last resort. (python -c is a good example of such a last resort, because you have no way to use actual linebreaks in that case.)

提交回复
热议问题