Home | | Computer Science 12th Std | Formatting characters

Python - Formatting characters | 12th Computer Science : Chapter 8 : Core Python : Strings and String Manipulation

Chapter: 12th Computer Science : Chapter 8 : Core Python : Strings and String Manipulation

Formatting characters

Escape sequences starts with a backslash and it can be interpreted differently.

Formatting characters


Escape sequence in python

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 sequences supported by python


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

Tags : Python , 12th Computer Science : Chapter 8 : Core Python : Strings and String Manipulation
Study Material, Lecturing Notes, Assignment, Reference, Wiki description explanation, brief detail
12th Computer Science : Chapter 8 : Core Python : Strings and String Manipulation : Formatting characters | Python


Privacy Policy, Terms and Conditions, DMCA Policy and Compliant

Copyright © 2018-2023 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.