{python31}class
2011-03-16 22:11
302 查看
代码:
# -*- coding: UTF-8 -*-
class T(object):
def __init__(self):
print('Construct T object:',self.data)
data=list(range(0,10))
print('In T class:',data)
t1=T()
print(t1.data)
执行结果:
In T class: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
Construct T object: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
似乎在class内分为语句与函数,首先执行class内的语句,然后执行class内的 __init__函数
# -*- coding: UTF-8 -*-
class T(object):
def __init__(self):
print('Construct T object:',self.data)
data=list(range(0,10))
print('In T class:',data)
t1=T()
print(t1.data)
执行结果:
In T class: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
Construct T object: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
似乎在class内分为语句与函数,首先执行class内的语句,然后执行class内的 __init__函数
相关文章推荐
- Python class 初始化参数为 list 等 可变类型时遇到的问题
- Python中的元类(metaclass)
- Python中的Class
- Python 实例方法、@staticmethod和@classmethod
- 「学习笔记——Python」Google's Python Class 学习笔记
- Python轻松入门-31 struct模块
- python decorators, classmethod and staticmethod
- python技巧31[Python 动态加载模块的3种方法]
- python的class的__str__和__repr__(转)
- 根据CI模式弄的一个python访问数据的class
- python学习之路(class)
- 转 Python 实例方法、@staticmethod和@classmethod
- python类库31[正则表达式之sub]
- python基础教程之类class定义使用方法
- python实例31[urllib.request.urlopen获取股票信息]
- python类库31[命令行解析]
- python_class 6. 0001 lec1
- python语法31[with来自动释放对象]
- chapter9: python 类的方法,属性,迭代器(new[old]-type class,[un]bound method,super,protocol,property,iterators)
- 如何写出优雅的Python之设置class缺省值