频道栏目
首页 > 资讯 > Python > 正文

关于python __call__() 方法

17-09-06        来源:[db:作者]  
收藏   我要投稿

tem.py

class temp(object):

def __init__(self,name):

self.name = name

def print(self):

print(self.name)

p = temp(10)

p()

这样会报错

但如果重写python 的 内置__call__,就可以实例调用

lass temp(object):

def __init__(self,name):

self.name = name

def print(self):

print(self.name)

def __call__(self)

print('hello,world')

p = temp(10)

p()

samuel@ubuntu:~$ python3 tem.py

hello world

相关TAG标签
上一篇:HDU -2018 母牛的故事
下一篇:C语言关键字及说明
相关文章
图文推荐

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训 | 举报中心

版权所有: 红黑联盟--致力于做实用的IT技术学习网站