In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article focuses on "what are the built-in methods and properties of Python". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn what are the built-in methods and properties of Python.
1.1 _ del_ method (known)
In Python
When an object is created with the class name (), the _ init_ method is called automatically after the object has been allocated space
The _ del_ method is called automatically before an object is phased out of memory
Life cycle
1) an object is created from the calling class name (), and the life cycle begins
2) once the _ del_ method of an object is called, the life cycle ends
3) during the life cycle of the object, you can access the properties of the object or have the object call the method
Class Cat (): def _ _ init__ (self New_name): self.name = new_name print ("% s is coming"% self.name) def _ del_ (self): print ("% s I went"% self.name) # tom is a global variable tom = Cat ("Tom") print (tom.name) # del keyword can delete an object del tom print ("-" * 50) 1.2 _ str_ method
In Python, print is used to output object variables. By default, the object referenced by this variable is output from which class created the object, as well as the address in memory (hexadecimal representation)
If, in development, you want to print custom content when you want to use print to output object variables, you can take advantage of the built-in method _ str_
Note:
The _ str_ method must return a string
Class Cat (): def _ _ init__ (self New_name): self.name = new_name print ("% s is coming"% self.name) def _ del_ (self): print ("% s I went"% self.name) def _ _ str__ (self): # must return a string return "I am a kitten [% s]"% self.name # tom is a global variable tom = Cat ("Tom") print (tom) so far I believe that you have a deeper understanding of "what are the built-in methods and properties of Python?" you might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue 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.