python-5th step for python :built-in function and class

built-in function
key char:
__ function_name__

dir(functionname)
will show this functions' built-in functhon

class
key char:
class Class_Name :
    def function_name (self, parament) :
        print
instantiation object :
object = Class_Name()

class Cat :
    def __init__(self,name) :
        self.name = name
    def eat(self) :
        print("cat love fish")
    def drink(self):
        print("cat drink"%self.name)
    def __del__(self) :
        print("%s is free !"%self.name)
    def __str__(self) :
       return "%s is printint"%self.name

tom = Cat("Tom")
tom.eat()
tom.drink()
print(tom)
the following 3 bulit-in function is the class' default function
_ _init__
it  define these parament for the object
__del__
excute before free the object
__str__
return the information when print the object


猜你喜欢

转载自blog.csdn.net/qq_14942375/article/details/80432983