Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialKrishna Pratap Chouhan
15,203 PointsString should be in single quotes or double quotes?
Why are the strings displayed in single quotes always. Despite of how we save them, when we print the strings we always find them in single quotes. Although there is no difference in single quotes and double quotes but still it happens. Is it simply a norm used by python? And if it is, in which case we could see a double quote in action, if any.
#In console.
sample_string = " A sample string"
sample_string
#output: 'A sample string'
sample_list = ["A sample string", "Another sample string"]
print(sample_list)
#output: ['A sample string', 'Another sample string']
2 Answers
Jennifer Nordell
Treehouse TeacherHi there! Single quotes and double quotes are used to enclose a string literal in Python. This is also true for other languages. It is my understanding that what is shown in the output is simply the preference of the developers of Python in how they display the string literal. They prefer to display it as single quotes and not double quotes. But both are equally valid, and they had to pick one
Here's some documentation regarding single quotes and double quotes.
Hope this helps!
Dylan Davenport
Courses Plus Student 2,645 PointsIt doesn't really matter if you use single or double quotes. It is sometimes better to use double quotes in a string if you are using contractions (don't, can't, didn't, etc.) If the string uses single quotes, when you go to use the contraction the program will see it as the single quote in the contraction ending the string. I hope that makes sense.