在调试时,我们经常会看到如下的print语句:
print x # easy to type, but no context
print 'x=',x # more context, harder to type
12
x= 12
Run Code Online (Sandbox Code Playgroud)
如何编写一个函数来获取变量或变量的名称并打印其名称和值?我只对调试输出感兴趣,这不会被合并到生产代码中.
debugPrint(x) # or
debugPrint('x')
x=12
Run Code Online (Sandbox Code Playgroud)