Why do we need special treatment of multiline string literals in programming languages? [duplicate] - programming-languages

This question already has an answer here:
What's the advantage of having multi-line & single-line string literals in python?
(1 answer)
Closed 8 years ago.
Python has """ for multiline string literals.
C/C++ use \ at the end of a line to split a string literal across multiple lines.
Go uses `` for the same.
Can a language not support multiline string literals only with a single quote character?
Why not have multiline string literals as the default and only supported form?

Python also support \ at the end of a line to split a string literal across multiple lines.

Related

Why doesn't multi line print in python work for single and double quoted strings? [duplicate]

This question already has answers here:
Why are three apostrophes needed for print in Python?
(4 answers)
How do I split the definition of a long string over multiple lines?
(30 answers)
Closed 2 years ago.
This program doesn't work
print("test
test")
This runs as expected
print("""test
test""")
Is this simply because Python interpreter allows multi line strings for triple quotes, or there is some difference in the way it interprets the triple quotes?
When You manually type \n it is interpreted as command to execute, you should use triple quotes to enter newlines(\n) manually. Either """#Your string""" or '''#Your string'''
the triple quotes are also used to define multi line string that why ,
print("""test
test""")
the above code works,
You can also use the \ such as,
print("test \
test")
Have a look at this question-Pythonic way to create a long multi-line string

How to calculate the length of a xterm control sequence [duplicate]

This question already has answers here:
How can I remove the ANSI escape sequences from a string in python
(8 answers)
Closed 3 years ago.
I am looking to format text before passing it to stdout/console. To do this properly I need to know how long a given section of text is after being printed to the console, which requires knowing how much characters will not be printed due to them being escape sequences.
On the web I have found multiple documentations for these sequence commands, but there seems to be no quick and easy way to find out where a given escape sequence command ends unless I was to parse them. Is there a trick/solution to getting the length of any escape sequence command without parsing?
How many characters is this \x1b[38;2;20;60;122m string \x1b[0m in console?
You can use ansifilter:
$ printf '\x1b[38;2;20;60;122mabc\x1b[0m' | ./ansifilter --no-trailing-nl | wc -c
3

Using double quotes inside a single quotes string changes escape behavior [duplicate]

This question already has answers here:
double quotes in string representation
(1 answer)
Understanding difference between Double Quote and Single Quote with __repr__()
(3 answers)
Closed 4 years ago.
Take a look at the following example:
In [1]: u'{u\'cname\': u"A\'B"}'
Out[1]: u'{u\'cname\': u"A\'B"}'
In [2]: u'{u\'cname\': uA\'B}'
Out[2]: u"{u'cname': uA'B}"
As you can see, the first string has additional pair of " in it, and it looks like this change is causing the entire escape logic to be altered - in the second example, there are no backslashed printed, while in the first one there are.
Why does this happen?
Thanks!

What Vim command(s) can be used to erase strings in double(or single) quotes and go insert mode? [duplicate]

This question already has answers here:
How to replace text between quotes in vi
(6 answers)
Closed 5 years ago.
I have documents that are full of double-quoted sentences. And using editors, It seems likely comfortable when 'erase strings surrounded by double(or single) quotes and go insert-mode' function embedded. Is there any way to do it using with vim?
Change inside quotes, ci" (or ci' for single-quoted strings)

python, \t works different when passed as argument (in Eclipse) [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Python: Split string with multiple delimiters
Convert django Charfield “\t” to tab
I have written a python code in Eclipse which takes delimiters as an argument. When I do
print "Hello",delimiter, "All".
This generates --> Hello \t All, whereas if I overwrite the delimiter with delimiter = '\t' within the code, I get the right output Hello All. I wonder what is the difference? I hope this not just the eclipse thing.
The problem is that what is being passed in from the command line is actually a string of length two "\\t" and not a tab character. You can do the following to your delimiter
delimiter.decode("string_escape"))
that should convert the string '\\t' into '\t'. The answer comes from a duplicate questions here

Resources