更新时间:2023-11-14 09:20:58
需要在函数定义中添加global counter
.(不在代码的第一行)
You need to add global counter
inside the function definition. (Not in the first line of your code)
你的代码应该是
counter = 0
def howManyTimesAmICalled():
global counter
counter += 1
print(counter)
howManyTimesAmICalled()