首页 > 其他 > 详细

面向对象-类与实例化对象

时间:2018-04-17 13:06:37      阅读:211      评论:0      收藏:0      [点我收藏+]

类:

一系列对象相似特征与技能的结合体

注:站在不同角度,分类不一样

在现实世界中:一定先有对象,再有类

在程序中:一定需先有类,再有对象

定义类并实例化对象:

#定义类
class LuffyStudent:
        school=luffycity
        def learn(self):
            print(is learning)
        def eat(self):
            print(is eating)
        def sleep(self):
            print(is sleeping)
#实例化对象
stu1=LuffyStudent()
stu2=LuffyStudent()
stu3=LuffyStudent()
print(stu1)
print(stu2)
print(stu3)

技术分享图片

 

 

面向对象-类与实例化对象

原文:https://www.cnblogs.com/yaya625202/p/8863527.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!