python中classmethod进行注释的方法
这篇文章主要介绍了python中classmethod进行注释的方法,具有一定借鉴价值,需要的朋友可以参考下。希望大家阅读完这篇文章后大有收获。下面让小编带着大家一起了解一下。

创新互联建站是一家专注于成都网站建设、网站制作与策划设计,惠济网站建设哪家好?创新互联建站做网站,专注于网站建设10余年,网设计领域的专业建站公司;建站业务涵盖:惠济等地区。惠济做网站价格咨询:18982081108
1.用法:
class C: @classmethod def f(cls, arg1, arg2, ...): ...
2.参数
无
3.返回值
返回函数的类方法。
4.classmethod 实例
class Data_test2(object):
day=0
month=0
year=0
def __init__(self,year=0,month=0,day=0):
self.day=day
self.month=month
self.year=year
@classmethod
def get_date(cls, string_date):
#这里第一个参数是cls, 表示调用当前的类名
year,month,day=map(int,string_date.split('-'))
date1=cls(year,month,day)
#返回的是一个初始化后的类
return date1
def out_date(self):
print "year :"
print self.year
print "month :"
print self.month
print "day :"
print self.day感谢你能够认真阅读完这篇文章,希望小编分享python中classmethod进行注释的方法内容对大家有帮助,同时也希望大家多多支持创新互联,关注创新互联行业资讯频道,遇到问题就找创新互联,详细的解决方法等着你来学习!
文章名称:python中classmethod进行注释的方法
网页URL:http://www.jxjierui.cn/article/jsopsj.html


咨询
建站咨询
