Single-Line vs. Double Quotes in Julia

What is the difference between single quotes and double quotes in Julia?

Unlike Python, for strings it does not allow single quotes:

> s = 'abc'
syntax: invalid character literal
> s = "abc"
> print(s)
abc

But when trying a single quote to use a double quote, it allowed:

> s = '"'
> print(s)
"

What is the use of single quotes in Julia? Is there documentation like Python PEP to explain why single quotes are not used?

+4
source share
1 answer

Think of it like in C / C ++; a single quote makes Char, and double quotes create a string (see, for example, here ).

julia> c = 'a'
'a'
julia> typeof(c)
Char
julia> s = "a"
"a"
julia> typeof(s)
String
julia> s = "ab"
"ab"
julia> typeof(s)
String

Python , ,

julia> typeof("abc"[1:1])
String    
julia> typeof("abc"[1])
Char

Python

>>> type("abc"[0:1])
<type 'str'>
>>> type("abc"[0])
<type 'str'>
+8

Source: https://habr.com/ru/post/1668996/


All Articles