class A{ private String a = "aa"; public boolean methodB(){ String b = "sb"; final String c ="adsf"; } } ------------------------------------------------- 正确答案是 a在堆中存放 bc在栈内存放. why? a属于类所以在堆中.bc属于方法,b c为局部变量,局部变量不属于任何类或者实例,因…
方法一: import inspectimport re def varname(p): for line in inspect.getframeinfo(inspect.currentframe().f_back)[3]: m = re.search(r'\bvarname\s*\(\s*([A-Za-z_][A-Za-z0-9_]*)\s*\)', line) if m: return m.group(1) 使用: >>> dsalds_ = 3 >>> varna…