简体   繁体   中英

Python White Spaces Style Guide

The Python Style Guide recommends not putting white spaces in expressions and statements. So, when I do these:

def testme( first_arg, second_arg ):
    pass

testme( 'a', 'b' )

and run pep8 against it, it will complain about the white spaces.

I know this is just a style guide so it should not affect the code but I want to understand the logic behind this style. To me, the white spaces gives more clarity. Is this something universally accepted in most programming language?

This is style, something that is an opinion. Wherever an opinion exists, people will disagree. That is fine and that is how it works.

But there's more. This is code - it's not only meant to be read by the next person, he/she will most likely also be editing the code.

And everything goes fine - until two people with different styles edit the same code that is. Everything will look different, the code will be confusing and bugs will start appearing.

But there's more. In Python whitespace is semantic , if you start mixing 4 spaces with tabs everything goes wrong. So having different styles in the same file (and same project for that matter) is even worse in Python than in most languages.

For this reason PEP 8 was created, an attempt to create an universal style guide for Python. It is of course your choice whether or not to follow this guide, but it is recommended.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM