python入门:静态方法、类成员方法
2018-03-22 10:04
225 查看
若有帮助到你,记得点赞哦!
参考:python基础教程第二版 Hetland
# -*- coding: utf-8 -*-
"""
Created on Thu Mar 22 09:52:45 2018
@author: Lelouch_C.C
"""
#"""
class MyClass:
def smeth():
print('lalala...')
smeth=staticmethod(smeth) #静态方法的定义没有self参数,且能够被类本身直接调用
def cmeth(cls):
print('hahaha...')
cmeth=classmethod(cmeth) #类成员方法定义了cls,类似于self,类成员方法可以直接用类的具体对象调用
print(MyClass.smeth())
print(MyClass.cmeth())
#"""
"""
class MyClass:
@staticmethod
# @操作符在方法或函数上方将装饰器列出,可指定多个装饰器,多个装饰器在应用时的顺序与指定顺序相反
def smeth():
print('lalala...')
#静态方法
@classmethod
def cmeth(cls):
print('hahaha...')
#类成员方法
print(MyClass.smeth())
print(MyClass.cmeth())
#"""
参考:python基础教程第二版 Hetland
# -*- coding: utf-8 -*-
"""
Created on Thu Mar 22 09:52:45 2018
@author: Lelouch_C.C
"""
#"""
class MyClass:
def smeth():
print('lalala...')
smeth=staticmethod(smeth) #静态方法的定义没有self参数,且能够被类本身直接调用
def cmeth(cls):
print('hahaha...')
cmeth=classmethod(cmeth) #类成员方法定义了cls,类似于self,类成员方法可以直接用类的具体对象调用
print(MyClass.smeth())
print(MyClass.cmeth())
#"""
"""
class MyClass:
@staticmethod
# @操作符在方法或函数上方将装饰器列出,可指定多个装饰器,多个装饰器在应用时的顺序与指定顺序相反
def smeth():
print('lalala...')
#静态方法
@classmethod
def cmeth(cls):
print('hahaha...')
#类成员方法
print(MyClass.smeth())
print(MyClass.cmeth())
#"""
相关文章推荐
- python中的静态成员方法 和 类成员方法
- Python的静态方法和类成员方法
- Python的静态方法和类成员方法
- Python的静态方法和类成员方法
- Python类成员方法与静态方法
- 详解Python中的静态方法与类成员方法
- Python入门简单的静态网页爬虫2.0 (实现各模块的具体方法)
- Python的静态方法和类成员方法
- Python的静态方法和类成员方法都可以被类或实例访问,两者概念不容易理清,但还是有区别的
- Python的静态方法和类成员方法
- C# 入门(5) 类和结构,静态,访问器,虚成员和抽象成员,扩展方法,操作符重载,匿名类型
- Python的静态方法和类成员方法 分类: python学习 2015-05-07 19:45 40人阅读 评论(0) 收藏
- python 静态方法,类成员方法
- Python的静态方法和类成员方法
- python中的静态方法和类成员方法
- python中的静态成员方法和类成员方法
- Python的静态方法和类成员方法
- Python的静态方法和类成员方法
- Python的静态方法和类成员方法
- Python的静态方法和类成员方法