22-python_类的定义
来源:互联网 发布:隐身侠加密软件 编辑:程序博客网 时间:2024/05/19 16:21
类
- 类的定义
- 实例化
- 对象属性/方法 的调用
1.1 语法
class 类名 :
成员变量
成员函数
1.2 注意
-类的方法(成员函数)中至少有一个形参
1.3 举例
>>> class MyClass :
... variableMember = 123
... def functionMember(self) :
... print "Hello, I'm a function member of MyClass"
...
- instance = className()
>>> instanceA = MyClass()
>>> instanceA.variableMember
123
>>> instanceA.functionMember()
Hello, I'm a function member of MyClass
>>>
... variableMember = 123
... def functionMember(self) :
... print "Hello, I'm a function member of MyClass"
...
>>> instanceA = MyClass()
>>> instanceA.variableMember
123
>>> instanceA.functionMember()
Hello, I'm a function member of MyClass
>>>
- 类的定义
- 实例化
- 对象属性/方法 的调用
1. 类的定义
1.1 语法
class 类名 :
成员变量
成员函数
1.2 注意
-类的方法(成员函数)中至少有一个形参
1.3 举例
>>> class MyClass :
... variableMember = 123
... def functionMember(self) :
... print "Hello, I'm a function member of MyClass"
...
2. 实例化 - 对象的创建
- 对象的三个特性: 句柄 属性 方法- instance = className()
>>> instanceA = MyClass()
3. 调用
>>> instanceA.variableMember
123
>>> instanceA.functionMember()
Hello, I'm a function member of MyClass
>>>
4. 完整的例子
>>> class MyClass :... variableMember = 123
... def functionMember(self) :
... print "Hello, I'm a function member of MyClass"
...
>>> instanceA = MyClass()
>>> instanceA.variableMember
123
>>> instanceA.functionMember()
Hello, I'm a function member of MyClass
>>>
- 22-python_类的定义
- python_类的继承
- Python_类的继承
- python_类的一些方法
- 23-python_类的方法
- python_类的实例化
- python_类的设计模式
- python_类
- Python_类
- python_文件的读取
- python_文件的读写
- python_文件的处理
- python_文件的copy
- python_文件的赋值
- python_类包装
- python_
- 25-python_类的属性-对象的属性
- Python_修改文件名的一部分
- (1.1.5)UVA 694 The Collatz Sequence (直叙式模拟)
- 如何设计一个优秀的API(转载)
- WCF 框架运行时类图
- Android中的Handler机制
- WP7 手机软件纪念 - 稍后读软件
- 22-python_类的定义
- ip识别地区+页面动态跳转
- POJ-1014-Dividing
- 实战 ASP.NET Web API
- 23-python_类的方法
- WCF 中 TCP 与 HTTP 性能简单比较
- 在 WCF 中使用高效的 BinaryFormatter 序列化
- cxGrid实现取消过滤和排序后定位到首行(单选和多选)
- php基础