python的类方法需要在方法前面加装饰器:@classmethod ,静态方法是在方法前面加装饰器:@staticmethod。

类方法、类属性是属于类自身,属于类自身的命名空间,和实例方法、实例属性不在一个命名空间下。

实例对象和类都可以直接调用类方法、实例方法和静态方法,区别在于:在类方法和静态方法内部不能调用实例属性。

class Base:
def __init__(self):
print "base begin..."
def prints(self):
print "print base..." class Base1:
def __init__(self):
print "base1 begin..."
def printss(self):
print "print base1..." class Base2(Base1,Base):
names = 'li'
def __init__(self,name):
self.name = name
def prints(self):
print "print objectmethod..."+self.name
@staticmethod
def printStatic():
print "print staticmethod..."
@classmethod
def printClass(cls):
print "print classmethod"+cls.names b = Base2('king')
b.prints()
b.printClass()
b.printStatic()
print b.names
Base2('jim').printStatic()
Base2('jim').printClass()
Base2('jim').prints()

最新文章

  1. 解决Asp.net Mvc中使用异步的时候HttpContext.Current为null的方法
  2. fastjson自动转化参数报错
  3. 介绍开源的.net通信框架NetworkComms框架 源码分析(七)ProtobufSerializer
  4. MYSQL:使用\G参数改变输出结果集的显示方式
  5. ETL工具与脚本实现之间的对比
  6. Bag Problem
  7. CI实践_Android持续集成
  8. js控制div是否显示
  9. C# rmi例子
  10. template_20_实现智能指针
  11. Android 虚拟机安装SD卡
  12. ServletContext中的转发
  13. jQuery Mobile基础
  14. Uva 1612 Guess
  15. 小白的Python之路 day5 logging模块
  16. Luogu3527 POI2011 Meteors 整体二分、树状数组、差分
  17. I2S接口介绍
  18. node.js中的http.response.end方法使用说明
  19. InstallShield卸载不彻底,残留大量dll文件
  20. 《GPU高性能编程CUDA实战》第九章 原子性

热门文章

  1. Ubuntu 14.04—Anaconda 相关
  2. Intellj idea 安装JUnit
  3. 【优先队列】-HDU4546比赛难度
  4. [HMLY]4.CocoaPods详解----制作
  5. UIAlerView、UIActionSheet 和UIAlertViewController(点击注销确认按钮实现)
  6. NodeJs md5 sha1加密
  7. svn checkout操作
  8. EFI Shell 命令说明
  9. 101个Linq例子(40-60)
  10. 用perl发送数据到钓鱼站