我想知道为什么打印此代码4而不是3。第四参考在哪里?
import sys
def f(a):
print(sys.getrefcount(a))
a = [1, 2, 3]
f(a)
Run Code Online (Sandbox Code Playgroud) 我希望看到该类的定义list_iterator。当我尝试使用功能显示其定义时,help出现错误。是否需要导入一个模块才能访问其帮助?
更准确地说,我想知道如何获得对迭代器迭代的可迭代对象的引用。例如:
l = [1,2,3,4,5]
it = iter(l)
print(type(it)) # this prints: list_iterator
# how to get a reference to l using it
Run Code Online (Sandbox Code Playgroud)
我很确定对象it具有对该对象的引用l。这个例子证明了这一点:
import sys
l = [1,2,3,4]
print(sys.getrefcount(l)) # prints 2
it = iter(l)
print(sys.getrefcount(l)) # prints 3
Run Code Online (Sandbox Code Playgroud)
因此,第三参考肯定来自 it
我想知道是否可以使用定义函数类型typedef,我尝试了以下语法:
typedef int (*) (void *, void *) order;
Run Code Online (Sandbox Code Playgroud)
但这是行不通的。错误信息 :expected identifier or '(' before ')' token