Elixir,num = [9],num被赋值给'\ t'

the*_*ing 2 elixir

iex> num = [9]
'\t'
Run Code Online (Sandbox Code Playgroud)

分配单个[9]列表会返回'\ t'.这是什么原因?

Gaz*_*ler 6

您可以在IEx中使用i帮助程序获取有关数据类型的更多信息:

iex> i [9]  
Term
  '\t'
Data type
  List
Description
  This is a list of integers that is printed as a sequence of characters
  delimited by single quotes because all the integers in it represent valid
  ASCII characters. Conventionally, such lists of integers are referred to as
  "char lists" (more precisely, a char list is a list of Unicode codepoints,
  and ASCII is a subset of Unicode).
Raw representation
  [9]
Reference modules
  List
Run Code Online (Sandbox Code Playgroud)

如果要检查原始表示,可以传递char_lists: falseinspect:

IO.inspect('abc', char_lists: false)
[97, 98, 99]
Run Code Online (Sandbox Code Playgroud)

  • `hd [9]`也会显示9. (2认同)