Python Object-Oriented programming

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.