Object-oriented: Classes and objects, classes are abstract, and are concepts. objects are real things. A class is a template for an object that is created by a class.
The class consists of three parts, 1. Class name. 2. Properties. 3. Methods
class Cat:
def Eat (self):
print ("Cat eats fish ...")
def run (self):
print ("The cat is Running")
def introduce (self):
print ("Age of%s:%s"% (self.name,self.age))
#创建对象
Cat=cat ()
#为对象中的属性赋值
cat.name= "Tom"
cat.age= "
cat.eat ()
Cat.run ()
cat.introduce ()
Cat1=cat ()
cat1.name= "Laomao"
cat1.age= "Max"
cat1.eat ()
Cat1.run ()
cat1.introduce ()
#打印结果为
The cat eats fish ...
The cat is running.
Tom's age is: 20
The cat eats fish ...
The cat is running.
Age of Laomao is: 40
Attention:
Cat1.introduce () is equivalent to Cat1.introduce (CAT1) but cannot be called directly by calling the method Cat1.introduce (CAT1)
Python Object-Oriented programming