【发布时间】:2018-09-30 15:14:55
【问题描述】:
我正在尝试定义返回变量名称的函数。
>>> def function(x):
... return(str(x))
...
>>> a = 1
>>> function(a)
'1'
我想定义以下函数。如何定义?
>>> a = 1
>>> function(a)
a = 1
【问题讨论】:
-
a = 1; b = a; function(a)的函数应该打印什么? -
你能解释一下为什么你需要这个来防止 XY 问题吗?
-
我更愿意将此问题标记为 Getting the name of a variable as a string 的副本,特别是将 OP 指向 this answer: "a name is a one-way reference to an对象。”
标签: python string python-3.x function