Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

There are several classifications of python class attributes

2025-03-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces several categories of python attributes, which are very detailed and have certain reference value. Friends who are interested must finish reading them.

Description

1. Built-in class properties. There are various built-in properties in the Python class. For example, _ dict_,_doc_,_name_ and so on.

To give the same example, I want to look at all the key-value pairs of employee1. Therefore, you can simply write the following statement that contains the class namespace:

2. User-defined attributes: attributes are created in the class definition. You can dynamically create new properties for an existing instance of a class.

Property can also be bound to the class name.

Are the public, protected, and private attributes, respectively.

Example

Class MyClass: def func (self): print ('Hello') # create a new MyClassob = MyClass () ob.func ()

Give a quick browse, the object is mainly to see everything around you. For example, dogs are the object of animals, and I am the object of human beings. Similarly, the same phone class can have different objects. This is very similar to the function calls we discussed. Let's understand this with an example:

These are all the contents of this article entitled "there are several categories of python attributes". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report