我的问题是如何在函数内保持"方法调用的数量"?
我的意思是在下面的例子中,替换活动在函数内发生了两次。但我所能做的就是运行一个计数器来检查:函数执行了多少次。
def replace (newString,i=[0]):
oldString = 'This is word. This is another sample word.'
newString = oldString.replace('word', 'WORD')
print(newString)
i[0]+=1
return i[0]
如何计算函数内方法调用的执行次数并抛出输出以在python中跟踪它?
Output:
This is WORD. This is another sample WORD.
1
Expected output:
This is WORD. This is another sample WORD.
2
答案 0 :(得分:0)
RegEx方法
This is WORD. This is another sample WORD.
2
输出:
input()