Python的类
2015-07-13 20:01
726 查看
Python的类
# coding=utf-8 __author__ = 'zyt' class Fruit(): name = None age = 0 def __init__(self): # 自动被调用 self.name = 'apple' self.age = 1 print '类名是', self.__class__.__name__ def set_name(self, nm): self.name = nm def show_name(self): print 'name is:', self.name if __name__ == '__main__': apple = Fruit() apple.show_name() apple.set_name('Red Fuji Apple') apple.show_name() print type(apple) print isinstance(apple, Fruit) 运行结果: 类名是 Fruit name is: apple name is: Red Fuji Apple <type 'instance'> True
相关文章推荐
- python 文件操作
- Python语法
- python中的xlrd 和xlwt资料集合
- python namedtuple
- Python--处理文献中单词,统计个数
- python程序(scrapy爬虫)在windows环境下开机定时自启动
- python requests的安装与简单运用
- Python 安装 pip package
- python简单获取数组元素个数的方法
- Python3 - 时间处理与定时任务
- python连接字符串的方法小结
- Python装饰器学习(九步入门)
- Hive中使用Python实现Transform时遇到Broken pipe错误排查
- python基础教程总结2——字符串
- CIFAR数据库预处理 (python)
- python_1(基础知识)
- python第三方库系列之二十--批量机器配置管理库SaltStack
- Python程序的创建步骤
- python mysql
- python中的set集合操作