What are the legal names in python language?
Python naming rules are as follows:
File names are all lowercase, underscores can be used
Packages should have short, lowercase names. Underlining can be added if it improves readability. Such as mypackage.
The specifications of modules and packages are the same. Such as mymodule.
classes always capitalize the first letter of a word string. Such as MyClass. Inner classes can use extra leading underscores.
Function & Method Function names should be lowercase, and underlined style words can be used to increase readability. Such as: myfunction, my_example_function.
Note: Mixed case is only allowed when this style is already dominant, in order to maintain backward compatibility.
Parameters of functions and methods
Always use "self" as the first parameter of instance methods. Always use "cls" as the first parameter of a class method. If a function parameter name conflicts with a reserved keyword, it is usually better to use a suffixing underscore than to use an abbreviation or odd spelling.
Global variables
For the from M import * import statement, if you want to prevent the global variables in the imported module from being imported, you can use the old specification and add a Leading underscore.
Note: Avoid using global variables
Variables
Variable names are all lowercase, with underscores connecting each word. For example, color = white
The variable name should not contain type information because Python is a dynamically typed language. Such as iValue, names_list, dict_obj, etc. are all bad names.
Constant
Constant names are all capital letters, with underscores connecting each word such as MAX_OVERFLOW, TOTAL.
Exceptions
are suffixed with "Error".
Specific naming method
mainly refers to the system reserved word naming method in the form of __xxx__. This kind of naming can also be used in projects. Its significance is that variables in this form are read-only. Try not to overload class member functions in this form. Such as
class Base(object): def __init__(self, id, parent = None): self.__id__ = id self.__parent__ = parent def __message__(self, msgid):
where __id__, __parent__ and __message__ all use system reserved word nomenclature.
The above is the detailed content of What are the legal names in python language?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Solution to permission issues when viewing Python version in Linux terminal When you try to view Python version in Linux terminal, enter python...

How to avoid being detected when using FiddlerEverywhere for man-in-the-middle readings When you use FiddlerEverywhere...

How to teach computer novice programming basics within 10 hours? If you only have 10 hours to teach computer novice some programming knowledge, what would you choose to teach...

When using Python's pandas library, how to copy whole columns between two DataFrames with different structures is a common problem. Suppose we have two Dats...

How does Uvicorn continuously listen for HTTP requests? Uvicorn is a lightweight web server based on ASGI. One of its core functions is to listen for HTTP requests and proceed...

Fastapi ...

Using python in Linux terminal...

Understanding the anti-crawling strategy of Investing.com Many people often try to crawl news data from Investing.com (https://cn.investing.com/news/latest-news)...
