Single and Double Quotes in Python

Hi everyone,

This should be a fairly quick question.

I have been going through the Python course and I have just done the section on lists. I have noticed that the lessons are using double quotes ( " " ) for strings and single quotes ( ’ ’ ) for items in a list.

Is this an industry standard, or at least a recommended one, among programmers?

Thank you!

https://www.codecademy.com/paths/computer-science/tracks/cspath-flow-data-iteration/modules/dspath-lists/projects/gradebook

There’s no right or wrong use of quotes. Just try to be consistent on how you use single or double quotes.
Some devs like to use double quotes for strings that will be presented to the user (makes it easier to find on the code).
Others do like codecademy does.

This is what Python’s guideline says:

In Python, single-quoted strings and double-quoted strings are the same. This PEP does not make a recommendation for this. Pick a rule and stick to it. When a string contains single or double quote characters, however, use the other one to avoid backslashes in the string. It improves readability.

2 Likes

@blog4247097350 welcome to the forums! Like @design8521863073 said, there is no real difference. But if you use double quotes then you can use apostrophes(’) without needing backslashes. i.e

"The shop's"

The apostrophe isn’t counted as the end of the string, because you are using double quotes.

1 Like

Okay, thank you for the clarification everyone.

I think I’m going to keep to the single quotes in lists. It makes the code look cleaner to my eye.