python中的静态方法和类方法
2017-08-29 16:44
246 查看
#coding=utf-8 import time import datetime # !/usr/bin/env python # _#_ coding:utf-8 _*_ class MyClass(object): message = "hello world" def show(self): print self.message print 'name is : %s, age is :%d' % (self.name, self.age) @staticmethod def printMsg(): print "print MSG" print MyClass.message @classmethod def people(cls, name, age): print "%s peope with %s is %d years old" % (cls.__name__,name,age) return cls(name, age) def __init__(self, name = "bai", age = 12): print "constructor", name self.name = name self.age = age MyClass.printMsg() people = MyClass.people("jack", 20) print people.name print people.age print people.message
相关文章推荐
- python的类方法和类的静态方法
- Python的静态方法和类成员方法都可以被类或实例访问,两者概念不容易理清,但还是有区别的
- Python的静态方法和类成员方法
- python 类的实例方法,静态方法,类方法辨析
- Python 多态 类属性 静态方法 简单工厂
- python实例、类方法、静态方法
- 静态方法 分类: python基础学习 2014-04-05 19:34 228人阅读 评论(0) 收藏
- python基础3--面向对象--类变量、实例变量、类方法、静态方法、实例方法
- Python的实例方法,类方法,静态方法之间的区别及调用关系
- python3 为类动态添加静态(类)方法 类名.方法名=方法名
- python中的实例方法、静态方法、类方法、类变量和实例变量浅析
- Python的静态方法和类成员方法
- python中类方法、类实例方法、静态方法的使用与区别
- python的类方法和类的静态方法
- 0005python中的静态方法和类方法
- Python:类方法、静态方法、实例方法
- Python的实例方法,类方法,静态方法之间的区别及调用关系
- python中类方法、类实例方法、静态方法的使用与区别
- python 浅析类方法与静态方法
- Python的类方法,静态方法,实例方法,类变量,实例变量,静态变量的总结