惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
U
Unit 42
IT之家
IT之家
Y
Y Combinator Blog
T
Tailwind CSS Blog
B
Blog
大猫的无限游戏
大猫的无限游戏
博客园 - 叶小钗
Jina AI
Jina AI
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
I
InfoQ
J
Java Code Geeks
F
Fortinet All Blogs
T
The Blog of Author Tim Ferriss
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
H
Hackread – Cybersecurity News, Data Breaches, AI and More
人人都是产品经理
人人都是产品经理
腾讯CDC
Hugging Face - Blog
Hugging Face - Blog
GbyAI
GbyAI
博客园 - 司徒正美
The GitHub Blog
The GitHub Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
L
LangChain Blog

博客园 - 紫色物语

多个nginx之间如何实现反向代理和负责均衡 docker相关知识 spring boot+mybatis 系列 springboot+dockfile @log的decorator完美实现(原创) 配置nginx输入任何地址都跳转至维护页面 0004python中的map,reduce,lambda,filter 0003python中的可变参数 0000python中文乱码解决方案 0002python中dict和list的特殊构造 0001python中特殊的for迭代zip函数 年度热门开源项目 SSO 不同服务器数据库之间的数据操作 自动构建部署 EF 性能调优 断点续传 gis 相关资料 easyui 特殊操作
0005python中的静态方法和类方法
紫色物语 · 2017-02-07 · via 博客园 - 紫色物语

#!/usr/bin/env python
# coding=utf-8

__metaclass__ = type

class StaticMethod:
@staticmethod
def foo():
print "This is static method foo()."

class ClassMethod:
@classmethod
def bar(cls):
print "This is class method bar()."
print "bar() is part of class:", cls.__name__

if __name__ == "__main__":
static_foo = StaticMethod() #实例化
static_foo.foo() #实例调用静态方法
StaticMethod.foo() #通过类来调用静态方法
print "********"
class_bar = ClassMethod()
class_bar.bar()
ClassMethod.bar()

C:\Users\Administrator>python d:\aa.py
This is static method foo().
This is static method foo().
********
This is class method bar().
bar() is part of class: ClassMethod
This is class method bar().
bar() is part of class: ClassMethod