Coding Exercise: The Great Escape
Write a program that prints the following: A double-quote's escaped using a backslash, e.g. \"
Note: there is more than one way to do this (as usual)! For example, you could enclose the whole string in single quotes, or in double-quotes. In either case, escaping is needed. For extra practice, solve the problem one way, and then solve it the other way. Can you solve it a third way?
solution:
#First way
print('A double-quote\'s escaped using a backslash e.g\\"')
#Second way
print("A double-quote's escaped using a backslash e.g\\'")
#Third Way
print(r "A double-quote's escaped using a backslash e.g\" ")
A raw string tells Python to ignore all formatting within a string, including escape characters. We create a raw string by putting an r in front of the string, right before the beginning quotation mark.
Python in IDLE pasted below.
Output Screen
please give me thumb up
Get Answers For Free
Most questions answered within 1 hours.