I'm getting stange results from triple """
quoted strings when using string interpolation and line breaks:
val foo = "bar"
s"""$foo"""
This is ok.
s"""
$foo
"""
This is wrong, I get the following output:
"
bar
"
Why the heck are there quotation marks?
Spanning strings over multiple lines can be done using python's triple quotes. It can also be used for long comments in code. Special characters like TABs, verbatim or NEWLINEs can also be used within the triple quotes.
The triple quotation is a nice way to be able to include other types of quotation within your string without having to use escape characters. For example: print("He said \"my name's John\"") That example requires escape characters \" to use double quote marks.
Enclosing Strings Containing Single and Double Quotes Actually, we can use triple quotes (i.e., triplet of single quotes or triplet double quotes) to represent the strings containing both single and double quotes to eliminate the need of escaping any. >>> print('''She said, "Thank you! It's mine."''')
String literals inside triple quotes, """ or ''', can span multiple lines of text.
This is just the REPL surrounding multi-line strings in quotation marks. You'll find the actual string contains no quotation marks:
res0.contains("\"")
res1 : Boolean = false
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With