It is quite difficult to answer the question of ‘How to print quotation marks in python?.’ This is because Python does not permit using double quotes inside of double quotes. In fact, it also does not permit using single quotes inside of single quotes. For example, ""Hello"" or ''Hello'' will show a syntax error. In this blog, we will solve this problem and show you how to do so easily.

How to print quotation marks in python?

Also Read: Python programming structure: Everything you need to know

How to print quotation marks in python?

You will be able to print quotes in a string in Python with the help of the following methods:

1. Using single quotes inside double quotes or in reverse

In order to print double quotes in a string in Python, you have to wrap the string with single quotes.

For example,

print('"Hello"')

Then, the output will be:

"Hello"

Now, in order to print single quotes in a string in Python, you have to wrap the string with double quotes.

For example,

print("'Hello'")

Then, the output will be:

"Hello"

If you want to print single quotes in a string in Python, you have to wrap the string with double quotes.

For example,

print("'Hello'")

Lastly, the output will be:

'Hello'

2. Using escape character \ before double or single quotes to print them in a string

Now we will use the escape character \ before double or single quotes to print them in a string.

For example,

print("\"Hello\"")
print('\'Hello\'')

Then, the output will be:

"Hello"
'Hello'

3. Using triple quote string for printing single or double quotes

Lastly, we will use a triple quote string for printing single or double quotes. The example is given below:

print(""" "Hello" """)
print(''' 'Hello' ''')
print(""" 'He"ll"o' """)
print(""" "He'll'o" """)

The Output is as follows:

"Hello"
'Hello'
'He"ll"o'
"He'll'o"

Conclusion on How to print quotation marks in python?

We hope that in this blog, you found the most suitable method for you to print quotation marks in Python. The procedure is easy enough and you will be able to do it easily. Thank you!

Categorized in: