How To Print A String That Contains Quotes In Python
I want to print quotes in python. Is it possible to print a ' in python or any other language? I tried print(''''). Here a & b are useless because it was giving inappropriate g
Solution 1:
There are a few ways:
Use single and double quotes together:
You are allowed to start and end a string literal with single quotes (also known as apostrophes), like 'blah blah'. Then, double quotes can go in between,
print ('"quotation marks"')
"quotation marks"
Escape the double quotes within the string:
You can put a backslash character followed by a quote (\" or \'). This is called an escape sequence and Python will remove the backslash, and put just the quote in the string.
print ("\"quotation marks\"")
"quotation marks"
Use triple-quoted strings:
print (""" "quotation marks" """)
"quotation marks"
Solution 2:
Wrap it in single quotes.
print('AAA " AAA " AAA')
# => AAA " AAA " AAA
Or escape the quotes:
print("AAA \" \" AAA ")
# => AAA " " AAA
Solution 3:
print(' \' ') # works with any quotesprint(" \" ") # works with any quotesprint(' " ') # only works for opposite quotes.print(" ' ") # only works for opposite quotes.
Solution 4:
You can print a quote by escaping it with the \ character.
print("\"")
The \ will cancel the next symbols syntactical meaning an use it as a character.
Post a Comment for "How To Print A String That Contains Quotes In Python"