The meaning and effect of single underline and double underline in Python

Source: Internet
Author: User

There is no real "private" in Python, and the visibility of the properties of a class depends on the name of the property (the property here includes the function). For example, attributes that start with a single underscore (for example , _spam) should be treated as non-public parts of the API (but note that they can still be accessed), which is generally the part of the specific implementation details. Single underline is commonly used for module-level privatization, and when we use "frommymodule import *" to load modules, module properties that begin with a single underscore are not loaded.

Attributes that start with a double underscore and end with a maximum of one underscore (for example, ___spam) will be replaced with _classname__spam, where ClassName is the class name of the current class. Knowing this, we still have access to Python 's private functions

The meaning and effect of single underline and double underline in Python

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.