I often talk about python's Private Public attributes (this article is required ).

Source: Internet
Author: User

I often talk about python's Private Public attributes (this article is required ).

In python, variables outside the class are called attributes, and variables in the class are called fields. Their private public access methods are similar.

Class C: _ name = "private property" def func (self): print (C. _ name) class sub_C (C): def info (self): print (C. _ name) # The private field obj = C () obj of the parent class cannot be accessed in the derived class. func () obj = sub_C () obj.info ()

Methods and attributes are accessed in a similar way, that is, Private Members can only be used within a class.

The previous article about python's private and public attributes (which must be read) is a part of the Content shared by Alibaba Cloud. I hope this article can be used as a reference and support for the customer's home.

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.