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 trial

Python Python Basics (2015) Python for Beginners Errors

Chris Bennett
Chris Bennett
1,328 Points

What 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
AJ Salmon
5,675 Points

Both are equal and what you use is completely up to your preference. Just try to stick to one of 'em throughout your script!

AJ Salmon
AJ Salmon
5,675 Points

I will add that " is useful when ' is inside the string, and vice versa.

Chris Bennett
Chris Bennett
1,328 Points

Thanks! I just want to make sure that I use Python correctly!

AJ Salmon
AJ Salmon
5,675 Points

Myt pleasure! It was a good question. Keep coding :)

Andrey Misikhin
Andrey Misikhin
16,529 Points

Both 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"