Docs for the multiline string with an initial escape is not correct in version 3.3+
This is correct: https://docs.python.org/3.2/tutorial/introduction.html Or, strings can be surrounded in a pair of matching triple-quotes: """ or '''. End of lines do not need to be escaped when using triple-quotes, but they will be included in the string. So the following uses one escape to avoid an unwanted initial blank line. print("""\ Usage: thingy [OPTIONS] -h Display this usage message -H hostname Hostname to connect to """) This is NOT correct: https://docs.python.org/3.3/tutorial/introduction.html String literals can span multiple lines. One way is using triple-quotes: """...""" or '''...'''. End of lines are automatically included in the string, but it’s possible to prevent this by adding a \ at the end of the line. The following example: print("""\ Usage: thingy [OPTIONS] -h Display this usage message -H hostname Hostname to connect to """)
Clarification, the example should be: print("""\ Usage: thingy [OPTIONS] -h Display this usage message -H hostname Hostname to connect to\ """) or print("""\ Usage: thingy [OPTIONS] -h Display this usage message -H hostname Hostname to connect to""") On Tue, Mar 22, 2022 at 9:01 AM Martin Bendsöe < martin.bendsoe@neotechnology.com> wrote:
This is correct:
https://docs.python.org/3.2/tutorial/introduction.html
Or, strings can be surrounded in a pair of matching triple-quotes: """ or '''. End of lines do not need to be escaped when using triple-quotes, but they will be included in the string. So the following uses one escape to avoid an unwanted initial blank line.
print("""\ Usage: thingy [OPTIONS] -h Display this usage message -H hostname Hostname to connect to """)
This is NOT correct:
https://docs.python.org/3.3/tutorial/introduction.html
String literals can span multiple lines. One way is using triple-quotes: """...""" or '''...'''. End of lines are automatically included in the string, but it’s possible to prevent this by adding a \ at the end of the line. The following example:
print("""\ Usage: thingy [OPTIONS] -h Display this usage message -H hostname Hostname to connect to """)
On 22. 03. 22 9:16, Martin Bendsöe via docs wrote:
Clarification, the example should be:
print("""\ Usage: thingy [OPTIONS] -h Display this usage message -H hostname Hostname to connect to\ """)
or
print("""\ Usage: thingy [OPTIONS] -h Display this usage message -H hostname Hostname to connect to""")
So, you're suggesting that the trailing newline should not be included in the string?
On Tue, Mar 22, 2022 at 9:01 AM Martin Bendsöe <martin.bendsoe@neotechnology.com <mailto:martin.bendsoe@neotechnology.com>> wrote:
This is correct:
https://docs.python.org/3.2/tutorial/introduction.html <https://docs.python.org/3.2/tutorial/introduction.html>
Or, strings can be surrounded in a pair of matching triple-quotes: """ or '''. End of lines do not need to be escaped when using triple-quotes, but they will be included in the string. So the following uses one escape to avoid an unwanted initial blank line.
print("""\ Usage: thingy [OPTIONS] -h Display this usage message -H hostname Hostname to connect to """)
This is NOT correct:
https://docs.python.org/3.3/tutorial/introduction.html <https://docs.python.org/3.3/tutorial/introduction.html>
String literals can span multiple lines. One way is using triple-quotes: """...""" or '''...'''. End of lines are automatically included in the string, but it’s possible to prevent this by adding a \ at the end of the line. The following example:
print("""\ Usage: thingy [OPTIONS] -h Display this usage message -H hostname Hostname to connect to """)
_______________________________________________ docs mailing list -- docs@python.org To unsubscribe send an email to docs-leave@python.org https://mail.python.org/mailman3/lists/docs.python.org/ Member address: encukou@gmail.com
participants (2)
-
Martin Bendsöe
-
Petr Viktorin