首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > perl python >

python 惯用函数举例

2013-01-26 
python 常用函数举例1 apply 函数def printInfo(id,name,address):print id is ,id, and name is ,nam

python 常用函数举例

1 apply 函数

def printInfo(id,name,address):
    print 'id is ',id,' and name is ',name,' and address is ',address

1.1 调用printInfo函数

printInfo(1,'flankwang','HeNan KaiFeng')

1.2 调用printInfo函数

apply(printInfo,(1,'flankwang','HeNan KaiFeng'))

1.1 和1.2效果一样


2 __call__ 函数

class CallDemo(object):
    def __init__(self):
        print 'this is __init__ method'
    def __call__(self):
        print 'this is __call__ method'

调用:

CallDemo()()

结果:

this is __init__ method
this is __call__ method

热点排行