I.. dir built-in function
- Enter A. After the identifier/data, and then press the TAB key, Ipython prompts the list of methods that the object can invoke
- After using the built-in function dir to pass in identifiers/data, you can view all the properties and methods within the object
# View the Comments demo. __doc_
Ii. Class 1, definition
The name of the big hump of class names
2. Create
Object variable = class name ()
3. Self parameter (which object invokes method, self is the reference to which object is similar to this)
(1), add attribute
# directly through the external code of the class. Set a property to " Tom "
(2), call properties
- Self. Accessing the properties of an object
- Self. Calling other object methods
(PS This method in the external assignment of properties is not recommended to use OH)
(3) Initialization method
The initialization method is called automatically when an object is created using the class name __init () __
Example:
(4) Built-in method
- __del__ method
- Del object (can delete an object) if not active del then the object will be executed after executing all code del
- __str__ method
- What to output when the object is output (must be a string)
- PS (within a pair of parentheses in Python can automatically connect when the line is changed)
4. Identity operator
Compares the memory addresses of two objects---whether a reference to the same object
When compared to none in Python, it is recommended to use is to determine
- is similar ID (x) = = ID (y)
- is not similar to ID (x) = = ID (y)
Third, private properties and methods
1. Definition method
when defining properties and methods, add two underscores to the property name and method name , which is defined as a private property or method
2. Pseudo-private properties and private methods
Python does not have a real sense of private
In fact, just give the name a few special treatment, so that the outside world can not access to
How to handle: precede the name with the _ class name _ Class name __ Name
Object-oriented Python (i)