Python: using 4 spaces for indentation. Why? [clos

2019-01-16 10:51发布

While coding python I'm using only 2 spaces to indent, sure PEP-8 really recommend to have 4 spaces, but historically for me it's unusual.

So, can anyone convince me to use 4 spaces instead of 2? What pros and cons?

P.S. And finally, what's easy way to convert all existing codebase from 2 spaces to 4 spaces?


P.P.S. PEP-8 Also srictly recommend not using tabs for indention. read here


So, to summarize:

Pros:

  • Have more space to arrange when wraping string more than 80 lines long.
  • Can copy code from snippets and it just works.

Cons:

  • With deeper level of nested statements you have less space for actual code.

Thanks.

13条回答
ゆ 、 Hurt°
2楼-- · 2019-01-16 11:39

using 4 spaces or 2 spaces is entirely up to you. 4 spaces is just a convention. What is most important, don't mix tabs and spaces. Use the space bar

查看更多
登录 后发表回答