在Python中,很容易创建一个字符串n:
>>> '=' * 40
'========================================'
Run Code Online (Sandbox Code Playgroud)
但是,在Julia中,上述方法不起作用.什么是Julia相当于上面的Python代码?
Jul*_*ner 11
在Julia中,您可以将单个字符复制到一个字符串中n,或者n使用^运算符将单个字符串复制到一个字符串中.因此,单引号字符'='或双引号单字符"="字符串将起作用.
julia> '='^40 # Note the single-quoted character '='
"========================================"
julia> "="^40 # Note the double-quoted string "="
"========================================"
Run Code Online (Sandbox Code Playgroud)
另一种做同样事情的方法是:
julia> repeat('=', 40)
"========================================"
julia> repeat("=", 40)
"========================================"
Run Code Online (Sandbox Code Playgroud)