朱莉娅字典中的反斜杠

时间:2015-04-08 20:31:11

标签: julia

我可以通过以下方式在朱莉娅快速创建字典:

julia> d = ['a' => 1, 'b' => 2 ]
Dict{Char,Int64} with 2 entries:
  'b' => 2
  'a' => 1

现在,我想将反斜杠字符作为我字典中的一个键。这会导致错误,因为它会转义'。相反,我尝试用另一个来逃避\。这不会导致错误,但也不能给我正确的结果。

julia> d = ['\\' => 3]
Dict{Char,Int64} with 1 entry:
  '\\' => 3

我错过了什么?

1 个答案:

答案 0 :(得分:4)

您获得了正确的值。 Julia通常会以您键入它们的方式尝试show值,而它们会在{"规范"}中print。表单(没有特殊语法)。

julia> show('\\')
'\\'
julia> print('\\')
\
julia> hex('\\')
"5c"
shell> man ascii | grep 5c
     58  X    59  Y    5a  Z    5b  [    5c  \    5d  ]    5e  ^    5f  _