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

后端 未结 2 1685
孤独总比滥情好
孤独总比滥情好 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.)

    0 讨论(0)
  • 2020-12-03 03:15

    I use semicolons in code all of the time. Our code folds across lines quite frequently, and a semicolon is a definitive assertion that a statement is ending.

    output, errors, status = generate_output_with_errors_and_status(
        first_monstrous_functional_argument(argument_one_to_argument
            , argument_two_to_argument)
        , second_argument);
    

    See? They're quite helpful to readability.

    0 讨论(0)
提交回复
热议问题