python coding style / python編程風格

來源:互聯網
上載者:User

標籤:

 

#from 《Python 2.7.9 documentation》

  • Use 4-space indentation, and no tabs.

  • #使用4空格縮排,不要使用tab縮排
  • Wrap lines so that they don’t exceed 79 characters.

  • 拆行確保每行不超過79個字元
  • Use blank lines to separate functions and classes, and larger blocks of code inside functions.

  • 函數和類之間用空行隔開,包括大塊程式碼片段也用空行隔開
  • When possible, put comments on a line of their own.

  • 注釋單獨佔一行
  • Use docstrings.

  • 使用文檔字串
  • Use spaces around operators and after commas, but not directly inside bracketing constructs: a = f(1, 2) + g(3, 4).

  • 操作符兩側和逗號後面留空格,但括弧裡側不加空格:a = f(1, 2) + g(3, 4)
  • Name your classes and functions consistently; the convention is to use CamelCase for classes and lower_case_with_underscores for functions and methods. Always use self as the name for the first method argument (see A First Look at Classes for more on classes and methods).

  • 統一類名和函數名,推薦類名用駝峰命名:SampleClass,函數名用小寫和底線命名:get_page(),盡量用self作為方法的第一個參數
  • Don’t use fancy encodings if your code is meant to be used in international environments. Plain ASCII works best in any case.

  • 國際化環境中慎用編碼,ASCII最佳。(中文環境下,推薦utf-8)

python coding style / python編程風格

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.