In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces the difference between python class properties and instance properties, which has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, let the editor take you to understand it.
1. Both class properties and instance properties are defined in the class, but the fundamental difference lies in the save location and the calling object.
2. Class properties can be accessed by classes and properties, while instance properties can only be accessed by instances.
This is because each time an instance object is created from a class, a memory space is opened up to store the properties and methods of the instance object, as well as pointers to the class object. An instance object can call a method in a class because it can access the class's properties and methods through the class object pointer.
Example
# here put the import lib class Dogs (object): # Class attribute belongTo = "Animals" def _ _ init__ (self Name): # instance properties self.name = name dog1 = Dogs ("Sunny Chen") print (Dogs.belongTo) # class properties access print (dog1.name) # instance properties access print (dog1.belongTo) # class properties can also be accessed by instances # print (Dogs.name) # but instance properties cannot be accessed by the class thank you for reading this chapter carefully I hope the article "what is the difference between python class properties and instance properties" shared by the editor is helpful to everyone. At the same time, I also hope that you can support and pay attention to the industry information channel, and more related knowledge is waiting for you to learn!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.