Because exceptions should be classes, the class naming convention applies here. However, you should use the suffix “Error” on your exception names (if the exception actually is an error). Global Variable Names (Let’s hope that these variables are meant for use inside one module only.) The...
The naming convention for functions may be used instead in cases where the interface is documented and used primarily as a callable. 注意,内建名称有一个单独的约定:大多数内建名称是单个单词(或两个单词一起运行),而CapWords约定仅用于异常名称和内建常量。 8.5 Type Variable Names 在PEP 484中引入的类...
As an example, here’s a new implementation of your old friend increment() without using a global variable inside the function. In this case, the function just takes a value as an argument and returns it incremented by one: Python >>> def increment(value=0): ... return value + 1...
single_trailing_underscore_: used by convention to avoid conflicts with Python keyword, e.g.Tkinter.Toplevel(master, class_='ClassName') 单下划线结尾_:只是为了避免与python关键字的命名冲突 __double_leading_underscore: when naming a class attribute, invokes name mangling (inside class FooBar, __bo...
Function and variable names Function names should be lowercase, with words separated by underscores as necessary to improve readability. 函数命名是小写单词, 以_连接(如果多个单词能提高可读性的话). Variable names follow the same convention as function names. ...
A module is a file containing Python definitions and statements. The file name is the module name with the suffix.pyappended. Within a module, the module’s name (as a string) is available as the value of the global variable__name__. For instance, use your favorite text editor to creat...
Public and Non-Public Variable Names A widely used naming convention for variables in Python is to use a leading underscore when you need to communicate that a given variable is what Python defines as non-public. A non-public variable is a variable that shouldn’t be used outside its defini...
Good Variable Naming Practices Choose meaningful names, such as roll_no, which is clearer than rn. Avoid unnecessarily long variable names (e.g., Roll_no_of_a_student is too long). Be consistent in your naming convention: roll_no or RollNo, but not both. ...
The data structures for these free lists now follow a naming convention: the variable is always named free_list, the counter is always named numfree, and a macro Py<typename>_MAXFREELIST is always defined. A new Makefile target, "make patchcheck", prepares the Python source tree for ...
Python Variable Naming Convention Before we start writing or declaring variables in Python, it is important to understand the rules for naming variables. Below are the 5 most important Python variables rules you must know: 1. The variable name should start with an underscore or letter. ...