python为什么调用带形参的函数可以不传参数

import re

p = re.compile(r'(\w+) (\w+)')
s = 'hello 123, hello 456'
def func(m):
return 'hi' + ' ' + m.group(2)
print p.sub(r'hello world', s) # 使用 'hello world' 替换 'hello 123' 和 'hello 456'
print p.sub(r'\2 \1', s) # 引用分组
print p.sub(func, s)
print p.sub(func, s, 1) # 最多替换一次

来源:http://funhacks.net/2016/12/27/regular_expression/

这个不是不传,是re模块自己传的match对象。
这个函数也只能是一个参数,这是re模块自己的机制
温馨提示:答案为网友推荐,仅供参考

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网