方法一: 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
打印变量db的类(class):[root@fuel ~]# pythonPython 2.6.6 (r266:84292, Jan 22 2014, 09:42:36)[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2Type "help", "copyright", "credits" or "license" for more information.>>>
python 对象/变量 对象 Every object has an identity, a type and a value. An object's identity never changes once it has been created; you may think of it as the object's address in memory. The 'is' operator compares the identity of two objects; the id() fun
Python的变量类型 变量可以指定不同的数据类型,这些变量可以存储整数,小数或字符. 变量赋值 Python 中的变量赋值不需要类型声明 等号(=)用来给变量赋值,等号左边为变量值,等号右边是存储在变量中的值 eg: a = b = c = 1 a, b, c = 1, 2, "john" #两个整型对象1和2的分配给变量 a 和 b,字符串对象 "john" 分配给变量 c. 标准数据类型 Number(数字) string(字符串) list(列表) t