How to Print Quotes in Python?


In Python, the print() function is used to print a statement or value on the screen. When you want to print a quotation, you need to use double quotes around the outside of the string, and then single quotes inside of the string. Otherwise, the quotation marks will be interpreted as part of the string.

For example, if you wanted to print the following quote:

“I am not a number! I am a free man!”

You would need to type the following into your Python console:

print('"I am not a number! I am a free man!"') # output: "I am not a number! I am a free man!"
Code language: PHP (php)

You need to know that there are two ways to print quotation marks in Python—with double quotes (“”) or with single quotes (”). Each method has its own benefits and drawbacks, which we will go over in detail.

Double Quotes

Printing double quotes is the most common way to print quotations in Python. To do this, simply surround your text with a pair of double quotes. For example, let’s say you wanted to print the following sentence:

I am reading “The Cat in the Hat” by Dr. Seuss.

In order to print this sentence using double quotes, your code would look like this:

print("I am reading \"The Cat in the Hat\" by Dr. Seuss.")
Code language: PHP (php)

Notice how we escaped the inner set of double quotes by placing a backslash () before them. This tells Python that we want to print the double quotes as part of our sentence, rather than using them to signify the end of the string. If we had omitted the backslash, our code would have given us an error because Python would have read the inner set of double quotes as the end of our string.

Single Quotes

Alternatively, we could have also printed our sentences using single quotes instead of double quotes. In this case, our code would look like this:

print('I am reading "The Cat in the Hat" by Dr Seuss.')
Code language: PHP (php)

Since we are using single quotes on the outside of our string, we don’t need to escape the inner set of double quotes—Python will automatically know that we want to print them as part of our string.

However, if we wanted to use an apostrophe within our string, we would need to escape it with a backslash since Python would otherwise interpret it as the end of our string.

For example:

print('You\'re doing a great job!')
Code language: PHP (php)

In this case, since we are using single-quoted strings on the outside, if we want to use an apostrophe inside our string (as in “You’re”), we need to escape it using a backslash. Otherwise, Python will interpret it as the end of our string.

In conclusion, there are two ways that you can print quotations in Python—with double quotes or with single quotes. Each method has its own benefits and drawbacks, which you should consider before deciding which one to use in your own code. Thanks for reading and happy coding!

Andy Avery

I really enjoy helping people with their tech problems to make life easier, ​and that’s what I’ve been doing professionally for the past decade.

Recent Posts