Escape Sequences
Characters
The Characters which
has some special function. Such type of charters are Escape
Sequences Characters.
List
of Escape Sequences Characters |
|
Escape Sequence |
Meaning |
\ |
Break
a Line into Multiple lines while ensuring the continuation of the line |
Inserts
a Backslash character in the string |
|
\' |
Inserts
a Single Quote character in the string |
\" |
Inserts
a Double Quote character in the string |
\n |
Inserts
a New Line in the string |
\t |
Inserts
a Tab in the string |
\r |
Inserts
a Carriage Return in the string |
\b |
Inserts
a Backspace in the string |
\u |
Inserts
a Unicode character in the string |
\0oo |
Inserts
a character in the string based on its Octal value |
\xhh |
Inserts
a character in the string based on its Hex value |
Example:
1. >>>
print("You can break \
… single line to \
… multiple
lines")
You can break a
single-line into multiple lines
2. >>>
print('print backslash \\ inside a string ')
print backslash \
inside a string
3. >>> print('print
single-quote \' within a string')
print single quote '
within a string
4. >>>
print("print double-quote \" within a string")
print double quote
" within a string
5. >>>
print("First line \nSecond line")
First line
Second line
6. >>> print("tab\tspacing")
tab spacing
7. >>>
print("same\rlike")
like
8. >>>
print("He\bi")
Hi
9. >>>
print("\u20B9")
10. >>>
print("\046")
&
11. >>>
print("\x24")
$
Comments
Comments
are a very important part of any program. A comment is a text that, ignored by
the Python interpreter. Comments are used to help you and other programmers
understand, maintain, and debug the program.
Python
uses two types of comments: single-line comments and multiline comments.
Single Line Comment
In
Python, the hash (#) symbol using for comment. Hash (#) symbol
makes all texts convert into a comment. For example,
#This
is single-line Python comment
Multiline Comments
If
the comment extends multiple lines, then one way of commenting on those lines
is to use
hash
(#) the symbol at the beginning of each line.
For
example,
#This
is
#multiline
comments
#in
Python
Another
way of doing this is to use triple quotes, either ''' or """.
These triple quotes are generally used for multiline strings. and
sometimes this type is called a doc-string. However, they can be used as a
multiline comment as well.
For
example,
'''This
is
multiline
comment
in
Python using triple quotes'''
Post a Comment