Formatting characters
Escape sequences starts with a backslash and it
can be interpreted differently. When you have use single quote to represent a
string, all the single quotes inside the string must be escaped. Similar is the
case with double quotes.
Example
#String within
triple quotes to display a string with single quote
>>> print ('''They said,
"What's there?"''')
They said, "What's
there?"
#String within
single quotes to display a string with single quote using escape sequence
>>> print ('They said,
"What\'s there?"')
They said, "What's
there?"
#String within double quotes to display a string with
single quote using escape sequence
>>> print ("They
said, \"What's there?\"")
He said, "What's
there?"
Escape Sequence : DESCRIPTION
\newline Backslash
and newline ignored
\\ Backslash
\' Single
quote
\" Double
quote
\a ASCII
Bell
\b ASCII
Backspace
\f ASCII
Form feed
\n ASCII
Linefeed
\r ASCII
Carriage Return
\t ASCII
Horizontal Tab
\v ASCII
Vertical Tab
\ooo Character
with octal value ooo
\xHH Character
with hexadecimal value HH
Related Topics
Privacy Policy, Terms and Conditions, DMCA Policy and Compliant
Copyright © 2018-2023 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.