python black_如何使用Black自动格式化Python代码

python black

Writing Python code is one thing and writing the code in a good format is another thing. Junior programmers often focus on making sure their code is working and forget to format the code properly along the way.

编写Python代码是一回事,以良好的格式编写代码是另一回事。 初级程序员经常专注于确保他们的代码正常工作,而忘记沿途正确格式化代码。

If you write a small program (with 1000 lines of codes) you can probably get away without formatting your code.

如果您编写一个小型程序(包含1000行代码),则可能无需格式化代码就可以逃脱。

But as programs get more and more complex, they get harder and harder to understand. At some point (around 15,000 lines of code), it becomes harder to understand the code that you yourself wrote.

但是,随着程序变得越来越复杂,它们变得越来越难理解。 在某个时候(大约15,000行代码),变得很难理解您自己编写的代码。

The difference between working on well-formatted code and working on badly formatted code is like the difference between living in a palace and living in a dirty house.

处理格式正确的代码与处理格式错误的代码之间的区别就像住在宫殿和脏房子里的区别。

为什么格式化python代码很重要 (Why formatting your python code is important)

可读性 (Readability)

Formatting your code will help you read your code efficiently. It looks more organized, and when someone looks at your code they'll get a good impression.

格式化代码将帮助您有效地 阅读代码。 它看起来更有条理,当有人查看您的代码时,他们会得到很好的印象。

这将有助于您的编码面试 (It will help in your coding interviews)

When you're in a coding interview, sometime the interviewers will care if you’re formatting your code properly. If you forget to do that formatting you might lose your job prospects, just because of your poorly formatted code.

在进行编码面试时,面试官有时会关心您是否正确设置了代码格式。 如果您忘记进行这种格式化,则可能会因为代码格式不正确而失去工作机会。

团队支持 (Team support)

Formatting your code becomes more important when you are working in a team. Several people will likely be working on the same software project and code you write must be understood by your teammates. Otherwise it becomes harder to work together.

团队中工作时,格式化代码变得更加重要 可能会有几个人在同一个软件项目上工作,并且您的队友必须理解您编写的代码。 否则,一起工作将变得更加困难。

轻松发现错误 (It makes it easy to spot bugs)

Badly formatted code can make it really, really

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值