InputForm[{a, b, c, d, e, f}]
提供{a, b, c, d, e, f}
InputForm[Characters["SOMETHING"]]
提供{"S", "O", "M", "E", "T", "H", "I", "N", "G"}
但为什么Drop[InputForm[Characters["SOMETHING"]],1]
不给{"O", "M", "E", "T", "H", "I", "N", "G"}
但是给出了一个InputForm []而没有别的?
我怎样才能做到这一点?
谢谢
答案 0 :(得分:4)
评估时
InputForm[Characters["SOMETHING"]]
Mathematica在内部产生结果
InputForm[List["S","O","M","E","T","H","I","N","G"]]
即。它是以InputForm
为首的表达式,其中包含ListList["S","O","M","E","T","H","I","N","G"]
作为其第一个子表达式。当Mathematica显示表达式时,您不会看到InputForm
头部,因为前端仅使用它作为如何显示表达式的提示,但它仍然存在于幕后
然后当你使用Drop[..., 1]
时,它会查看它给出的表达式,选出第一个子表达式,即List["S","O","M","E","T","H","I","N","G"]
,并将其丢弃。这只留下InputForm[]
。
进行类比:如果你评估了
Drop[List[List["S","O","M","E","T","H","I","N","G"]], 1]
你会理解为什么你会得到一个空列表,对吧?发生了同样的事情。