Naming conventions play an important role in writing code , Using naming conventions can make it more intuitive to understand what the code stands for , Make the code readable 、 Ease of writing and clarity .
Today I want to talk to you about Python Common naming and naming conventions .
Camel nomenclature (Camel-Case) The word comes from Perl A mixed case format commonly used in languages , It is also called hump nomenclature , It is a set of naming rules for computer programming ( practice ), There is no absoluteness or compulsion , To increase recognition and readability .
It's a mixture of uppercase and lowercase letters to form the names of variables and functions , It is divided into small hump nomenclature and large hump nomenclature
Except for the first word , All other words are capitalized .
The great hump method ( Pascal nomenclature ) Words are capitalized .
It's all made up of lowercase letters and underscores , Words are in lowercase and underlined , Also known as “ Underline nomenclature ”.
Underline the words “-” Connect , Also known as spine nomenclature (spinal-case)、train-case.
The variable names are followed by the attributes 、 type 、 Describe the composition , Such as :int iUserName,i by int Type abbreviation ,UserName Is to describe .
Mixed case , Along with the gender ……
Variable
The variable name must be a valid identifier ;
Variable names do not use Python Reserved word in ;
Use small letters with caution l And capital letters O;
Use meaningful words as variables ;
Try to be lowercase , If there are more than one word , Separate with an underscore, that is, use the snake naming method (snake_case) name .
i = 0
if i>0:
number = 0,
school_name= " Tsinghua"
Constants are in uppercase , Such as multiple words , Separate... With underscores .
PAI=3.14
MAX_CONNECTION=100
CONNECTION_TIMEOUT=500
All lowercase when there is only one word , When there are more than one word, use the serpentine nomenclature (snake_case) name .
def function():
pass
def function_name():
pass
Private functions place an underline before the function .
classPerson():
def _private_func():
pass
The class name uses camel hump (CamelCase) Naming style , title case , Private classes can start with an underscore .
class ClassName():
pass
Snake nomenclature is recommended (snake_case).
impor module_name
import html_parser
Finally, thank everyone who reads my article carefully , Watching the rise and attention of fans all the way , Reciprocity is always necessary , Although it's not very valuable , If you can use it, you can take it
These materials , For those who want to engage in 【 software test 】 For our friends, it should be the most comprehensive and complete war preparation warehouse , This warehouse also accompanied me through the most difficult journey , I hope it can help you ! You can get it for free by joining our communication group below , I hope that's helpful …….