What is Python Multiline Strings
Python multiline string(or block string) is a string which is spread over multiple lines and also new line characters are preserved. A python multiline string looks like this:
There are basically two native methods and one hacked method.
Using the “\” character. Actually “\” character allows us to spread the string over multiple lines but it doesn’t preserve new line characters. Therefore if you are using this method then remember to put new line characters manually. So we can say “\” allows us to create line concatenated string.
We can use ECMAScript 6 Template String to achieve the same type of multiline string as python.
Many browsers don’t yet support ECMAScript 6 therefore the above example may not work.
ECMAScript 6 template string also support string substitution feature as shown in the above example.
Let’s see an example of this:
You can also achieve string substitution using more advanced regular expression functionality.
- Uglify: Use /*@preserve instead of /* and enable the comments option
- Closure Compiler: Use /*@preserve instead of /*
- YUI Compressor: Use /*! instead of /*