Python面向对象
来源:互联网 发布:域名管理中心 编辑:程序博客网 时间:2024/06/06 05:32
#----------------面向对象----------------# 成员方法:方法中有self# 类方法 : 无self# __代表私有class people: name = '' age = 0 __weight = 0 #私有属性 def __init__(self,n,a,w): self.name = n self.age = a self.__weight = w def speak(self): print("%s 说: 我 %d 岁。" %(self.name,self.age))p = people('runoob',10,30)p.speak()# 继承class student(people): grade = '' def __init__(self,n,a,w,g): people.__init__(self,n,a,w) self.grade = g def speak(self): print('{} 说: 我 {} 岁。在读{}年级'.format(self.name,self.age,self.grade)) def speak1(): print('这是一个类方法')s = student('jack',22,60,'大三')s.speak()student.speak1()# 多重继承,逗号分隔# 方法重写 直接重写不需要关键字class privateTest: __a = 0 #私有属性 #私有方法 def __privateMethod(self): return '123' def __init__(self, arg): super(privateTest) self.arg = arg''' 类的专有方法: __init__ : 构造函数,在生成对象时调用 __del__ : 析构函数,释放对象时使用 __repr__ : 打印,转换 __setitem__ : 按照索引赋值 __getitem__: 按照索引获取值 __len__: 获得长度 __cmp__: 比较运算 __call__: 函数调用 __add__: 加运算 __sub__: 减运算 __mul__: 乘运算 __div__: 除运算 __mod__: 求余运算 __pow__: 称方'''
0 0
- python 面向对象
- python面向对象初步
- python面向对象
- Python面向对象详解
- python面向对象编程
- python面向对象
- python 面向对象
- python 面向对象编程
- python面向对象编程
- python面向对象编程
- python 面向对象笔记
- Python 面向对象编程
- Python面向对象编程
- python面向对象1
- Python面向对象详解
- Python 面向对象编程
- python面向对象1
- Python面向对象基础
- 文件上传的工具类(UploadUtils)
- SQLCookBook-元数据查询
- HDU4635-Strongly connected
- MAC升级到10.12.4 SVN CornerStone 一直连接不上的问题 2017年5月16更新
- sql表连接
- Python面向对象
- 学习笔记的总结和回顾(2017.2.14)
- 按钮圆角设置、html基础css引入
- 解决WIN10系统下PL2303_USB转串口驱动兼容性问题
- 双网卡内外网配置、route、网卡别名
- Swagger配置(SpringMVC、SpringBoot)
- tomcat优化
- Spring添加slf4j
- 减少前端代码耦合的几个方法