【发布时间】:2022-11-02 17:11:59
【问题描述】:
我想遍历变量列表并输出变量名称和值。例如,假设我有 x=1 和 y=2,那么我想要一个输出
x is 1
y is 2
我怀疑我需要为此使用符号。这是我的方法,但它不起作用:
function t(x,y)
for i in [x,y]
println("$(Symbol(i)) is $(eval(i))") # outputs "1 is 1" and "2 is 2"
end
end
t(1, 2)
有没有办法做到这一点?我想字典会起作用,但有兴趣看看符号是否也可以在这里使用。
【问题讨论】: