Python Escape Character and new line

 



Python 4:- Watch Video - Click here

Python Escape Character and new line

Program 5 Escape Character ( \ )

To insert characters that are illegal in a string, use an escape character.

An escape character is a backslash \ followed by the character you want to insert.

An example of an illegal character is a double quote inside a string that is surrounded by double quotes:

Example:

You will get an error if you use double quotes inside a string that is surrounded by double quotes:

Print (“He said,”My Name is Manoj Kumar”” )

To fix this problem, use the escape character \":

Print (“He said,\”My Name is Manoj Kumar\”” )

Other escape characters used in Python:

Code

Result

\'

Single Quote

\\

Backslash

\n

New Line

\r

Carriage Return

\t

Tab

\b

Backspace

\f

Form Feed

\ooo

Octal value

\xhh

Hex value

 

Program 6 Line Break ( \n )

Python Multiline String provides an efficient way to represent multiple strings in an aligned manner. A newline(\n) character can be added to multiline string as shown below–

Example:

Print (“Hello Friends.\nMy Name is Manoj Kumar.\nHow are you?”)

Output:

Hello Friends

My Name is Manoj Kumar.

How are you.

Python 4:- Watch Video - Click here

<< Previous                                                                  Next >> 

कोई टिप्पणी नहीं

टिप्पणी: केवल इस ब्लॉग का सदस्य टिप्पणी भेज सकता है.

Send Multiple Emails From Excel | Send Bulk Mail from Excel Sheet with Attachment in One Click

Send Multiple Emails From Excel | Send Bulk Mail from Excel Sheet with Attachment in One Click Download VBA Code Notepad file - Click here D...

Blogger द्वारा संचालित.