使用python将变量名转换成相应的字符串。
可以使用内置函数str()将变量转换为字符串类型,例如:
x = 123
y = "hello"
z = [1, 2, 3]
x_str = str(x)
y_str = str(y)
z_str = str(z)
print(type(x_str), x_str)
print(type(y_str), y_str)
print(type(z_str), z_str)
输出:
<class 'str'> 123
<class 'str'> hello
<class 'str'> [1, 2, 3]
原文地址: https://www.cveoy.top/t/topic/gSjx 著作权归作者所有。请勿转载和采集!