Reputation: 14521
I am trying to define a string in Julia like I would in Python by doing the following:
'hello world'
However, I am getting the following error:
ERROR: syntax: character literal contains multiple characters
Stacktrace:
[1] top-level scope
@ none:1
Any suggestion to resolve this? I searched around for the error but nothing about Julia came up, only C# and other languages.
Upvotes: 0
Views: 2875
Reputation: 42214
Your answer is not complete without noting that in Julia you have also """
help?> """
""" is used to delimit string literals. Strings created by triple quotation marks
can contain " characters without escaping and are dedented to the level of the
least-indented line. This is useful for defining strings within code
that is indented.
Examples
≡≡≡≡≡≡≡≡≡≡
julia> """Hello World!"""
"Hello World!"
julia> """Contains "quote" characters"""
"Contains \"quote\" characters"
julia> """
Hello,
world."""
"Hello,\nworld."
Upvotes: 3
Reputation: 14521
In languages like Python, it is possible to define a string with a single quote like this:
'this is a valid python string'
However, in Julia, the single quote can only be used for an individual character. If you have more than one, you need to use double quotes:
"This is a valid Julia string"
#vs
'This is NOT a valid string'
Upvotes: 1