Define class attributes and object attributes in python

Source: Internet
Author: User

In python, variables are of no type and can be bound to any type, but cannot be declared in syntax.

So how can we name a variable?

F = None

In this way, we bind a variable to each None type, and we can re-bind other types at any time. In this way, we have achieved the effect of preemptible variables.

How do I define the attributes and object attributes of a class?

If you have some knowledge about OO, you should know that the class attributes belong to the class as a whole, and the image attributes belong to specific image instances (view the implementation of gtk's Image System for further understanding ).

Class MyClass: cName = None def _ init _ (self): self. oName = "name"

In this way, cName is the class attribute, while oName is the object attribute.

Related Article

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.