我想打印一个列表以及
之类的字符串标识符list = [1, 2, 3]
IO.puts "list is ", list
这不起作用。我尝试了一些像
这样的变化# this prints only the list, not any strings
IO.inspect list
# using puts which also does not work
IO.puts "list is #{list}"
在javascript中,我可以简单地执行console.log("list is ", list)
。我很困惑如何在灵药中实现同样的目标。
答案 0 :(得分:11)
从Elixir 1.4开始,IO.inspect/2
接受label
选项among others:
IO.inspect list, label: "The list is"
#⇒ The list is: [1, 2, 3]
答案 1 :(得分:4)