[Language]Python的面向对象
来源:互联网 发布:投资网络销售好做吗 编辑:程序博客网 时间:2024/05/16 06:24
简述
Python支持函数式编程,也支持面向对象编程。
类
定义一个类:
class ClassName(base_class[es]): "optional documentation string" static_member_declarations method_declarations
类的示例:
class FooClass(object): """my very first class: FooClass""" version = 0.1 # class (data) attribute-静态变量,被所有实例及下面4个方法共享def __init__(self, nm='John Doe'): """constructor""" # __init__为特殊方法(以__开始和结尾的都是特殊方法,在类实例创建完毕后会自动执行__init__,其仅仅是对象创建后执行的第一个方法) self.name = nm # class instance (data) attribute print('Created a class instance for', nm)def showname(self): # self是类实例自身的引用,像其他语言中this """display instance attribute and class name""" print('Your name is', self.name) print('My name is', self.__class__.__name__)def showver(self): """display class(static) attribute""" print(self.version) # references FooClass.versiondef addMe2Me(self, x): # does not use 'self' """apply + operation to argument""" return x+x
0 0
- [Language]Python的面向对象
- python的面向对象
- 面向对象的python(一)
- 面向对象的python(二)
- Python面向对象的编程
- python 面向对象的编程
- Python面向对象的编程
- python面向对象的继承
- python面向对象的理解
- python的面向对象基础
- python-面向对象的基本概念
- python面向对象的编程
- 【Python】Python的面向对象机制
- [Language]Python的模块
- [Language]Python的多线程
- 3.面向对象的解释语言python
- Python的面向对象之class初览
- 关于Python的面向对象概念
- butterknife-空指针异常
- 张瑞书市长调研经济开发区康姿百德重点项目建设
- Python Assert
- Linux下特别权限位
- RN中关于 popToRoute的用法更正
- [Language]Python的面向对象
- Java统计字符串中每个字符(单词)个数
- 程序设计模式(六) C++ 适配器(Adapter)模式
- 《操作系统》第6章:并发:死锁和饥饿
- Android源码网站
- [RK3288][Android6.0] 调试笔记 --- 读取当前DDR频率方法
- 使用Quartz实现任务调度
- Building Shops(动态规划)
- jquery实现图片轮播【一般用于网站首页】