標籤:
#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編程風格