python基础-----面向对象编程
来源:互联网 发布:程序员月度工作总结 编辑:程序博客网 时间:2024/05/16 07:29
class Animal(object): mao = 'mao' #静态字段 --》》属于类 #在__init__ 方法中的属于动态字段 --->>属于对象 相当于构造函数 def __init__(self, name, age, sex, feet): self.name = name self.age = age #定义一个私有字段 self.__sex = sex self.__feet = feet #动态方法 def sport_meet(self): print self.name + 'run....' def FwSex(self): print "访问私有字段"+self.__sex #静态方法 @staticmethod def Foo(): print 'fly...' #把方法访问的形式变成字段访问的形式 @property def voice(self): print self.name+"voice..." return 'voice' #用property一般都带返回值 #定义一个私有方法 def __PrivateMethod(self): print 'privateMethod....' #本身共有方法,可以访问私有方法 def PublicMethod(self): self.__PrivateMethod() @property #只读 def Feet(self): return self.__feet @Feet.setter #只写 def Feet(self, feet): self.__feet = feet animal = Animal('天气', 34, '__sex','1111')# print animal.name# print Animal.Foo()# print animal.voice# # # print animal.__sex #访问报错(Animal instance has no attribute '__sex')# print animal.FwSex()# # animal.__PrivateMethod() #访问不了私有方法报错(Animal instance has no attribute '__PrivateMethod')print animal.Feetanimal.Feet = '12222'print animal.Feet
0 0
- python面向对象编程基础
- Python面向对象编程基础
- Python面向对象编程基础
- python面向对象编程基础
- python 面向对象编程-基础
- Python面向对象编程基础
- python基础-----面向对象编程
- Python 面向对象编程(一)基础
- python基础学习笔记<面向对象编程>
- Python面向对象编程基础学习笔记
- python之面向对象编程基础
- Python基础之五面向对象编程
- python基础八_面向对象编程
- Python 之 基础面向对象编程
- Python基础学习--第十二篇(面向对象编程基础)
- Python基础进阶篇——面向对象编程基础
- Python编程基础之十二面向对象编程
- Python面向对象基础
- 享元模式
- IE9及以下版本检测提示升级
- CodeForces
- 关于iframe
- 操作系统基础
- python基础-----面向对象编程
- 关于struts2中的显示页面乱码问题
- Caffe 学习:Eltwise层
- java关键字之—this
- css3动画过渡
- DHTML技术综合演示---示例:下拉风格的菜单条
- K-近邻算法的Python实现(一)
- Win7如何简单的关闭445端口及445端口入侵详解
- JavaScript一些常用方法一