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 trialChris Bennett
1,328 PointsWhat is the difference between ' and " in python?
When using python I can run a script using both ' and " is there a difference that I should know about and do they perform differently?
2 Answers
AJ Salmon
5,675 PointsBoth are equal and what you use is completely up to your preference. Just try to stick to one of 'em throughout your script!
Andrey Misikhin
16,529 PointsBoth variants works the same way. You can use both of them, for example in a string to avoid \ symbol.
str = "Hello 'beautiful' world"
str = 'Hello "beautiful" world'
str = 'Hello \'beautiful\' world'
str = "Hello \"beautiful\" world"
AJ Salmon
5,675 PointsAJ Salmon
5,675 PointsI will add that " is useful when ' is inside the string, and vice versa.
Chris Bennett
1,328 PointsChris Bennett
1,328 PointsThanks! I just want to make sure that I use Python correctly!
AJ Salmon
5,675 PointsAJ Salmon
5,675 PointsMyt pleasure! It was a good question. Keep coding :)