Programming Languages - Strings
Quotes
A raw string literal is a string in which the escape characters like \n
, \t
or \"
are not processed.
C++
- Single quote (
'
): single character - Double quote (
"
): string
Raw string literal:
R "delimiter( raw_characters )delimiter"
delimiter
is optional. One common usecase is to create ProtoBufs in tests:
R"pb({
...
})pb";
Java
- Single quote (
'
): single character - Double quote (
"
): string - Text blocks:
String foo = """
bar
baz
""";
Python
Single quotes ('
) and double quotes ("
) are quivelent.
Backtick quoting is generally non-useful and gone in Python 3.
Multiline strings: triple quotations using either single quotes '''
or double quotes """
.
Python docstrings (triple quotations using either single quotes '''
or double quotes """
) are the string literals that appear right after the definition of a function, method, class, or module.
def foo():
'''This is the docstring.'''
pass
JavaScript
Single quotes ('
) and double quotes ("
) are quivelent.
Template literals (Template strings) (`
):
- allow for multi-line strings.
- string interpolation, e.g.
hello ${name}!
.
Go
- Double quote (
"
): need to escape special characters, e.g."\n"
is a single character - backtick (
`
): raw string literals, no escape.