Q:

Python | Ignoring escape sequences in the string

belongs to collection: Python String Programs

0

First see, how escape sequence works?

In the below example, we are using some of the escape sequence and their outputs, we are printing single quote (\'), double quotes (\"), printing path (double slash) (\\) and using hexadecimal values (\x).

 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program:

#printing single quote
str1 = "Hi, I\'m IncludeHelp"	
#printing double quotes
str2 = ""Hello world""
#printing path
str3 = "D:\\work_folder\\python_works"
#using hexadecimal values
str4 = "This is  \x49\x6E\x63\x6C\x75\x64\x65\x48\x65\x6C\x70"

print(str1);
print(str2);
print(str3);
print(str4);

Output

Hi, I'm IncludeHelp
"Hello world"
D:\work_folder\python_works 
This is  IncludeHelp 

Ignoring Escape Sequences

To ignoring escape sequences in the string, we make the string as "raw string" by placing "r" before the string"raw string" prints as it assigned to the string.

Program:

#ignoring escape sequences

#ignoring single quote escape sequences
str1 = r"Hi, I\'m IncludeHelp"	
#ignoring double quotes escape sequences
str2 = r""Hello world""
#ignoring path escape sequences
str3 = r"D:\\work_folder\\python_works"
#ignoring hexadecimal values escape sequences
str4 = r"This is  \x49\x6E\x63\x6C\x75\x64\x65\x48\x65\x6C\x70"

print(str1);
print(str2);
print(str3);
print(str4);

Output

Hi, I\'m IncludeHelp  
"Hello world" 
D:\\work_folder\\python_works  
This is  \x49\x6E\x63\x6C\x75\x64\x65\x48\x65\x6C\x70

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Python String Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Python program to calculate the number of all poss... >>
<< Python | How to print double quotes with the strin...