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
Michael Melton
1,475 PointsWhy is ' vs. " being used around opensesame?
Why is ' vs. " being used around opensesame?
1 Answer
Jeff Muday
Treehouse Moderator 28,732 PointsUnlike some other languages, in Python, one can enclose strings with either the single quote or the double-quote character -- there's a functional equivalency. Whether you choose to use single-quote or double-quote delimitation is a stylistic choice of the programmer.
The nice thing is that a double-quote delimited string can contain single-quote punctuation and single-quote delimited strings can contain double-quote characters.
Valid strings:
x = "He said, I can't do that"
y = 'She said, "Hi!"'
Invalid strings:
x = 'He said, I can't do that'
y = "She said, "Hi!""
But you can use the backward-slash, called an escape like below:
x = 'He said, I can\'t do that'
y = "She said, \"Hi\""
I hope this helps answer your question. Good luck with your Python journey!
Michael Melton
1,475 PointsMichael Melton
1,475 PointsPython Basics > While Loops ~2:44-9:04