什么是这个C/C++代码的惯用Python等价物?
void foo()
{
static int counter = 0;
counter++;
printf("counter is %d\n", counter);
}
Run Code Online (Sandbox Code Playgroud)
具体来说,如何在功能级别实现静态成员,而不是类级别?将函数放入类中会改变什么吗?
是否可以在 python 中编写一个函数,它接受一个参数 a 并打印 h+a 的结果,其中 h 是一个局部变量。然后它应该返回自身,h 增加一。