• vaboro
What is the difference b/w single quotes and double quotes? Why do I see them used interchangeably in numerous examples? When should single quotes be used and when double quotes?
MIT 6.00 Intro Computer Science (OCW)
  • Stacey Warren - Expert
Hey! We 've verified this expert answer for you, click below to unlock the details :)
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
  • chestercat
I got my questions answered at in under 10 minutes. Go to now for free help!
  • anonymous
they accomplish the same function. it just depends on what youre trying to print. if youre trying to print something like. "He went to the store," said the boy. you would type print '"He went to the store", said the boy.' whenever you type the first quote it will look for the next instance of that particular character to terminate the string. so you can put double quotes inside single quote or single quotes inside double quotes. you can additionally use all the same kind of quotes and just put a "\" infront of the quotes you want to appear in the string. so the earlier example would be print "\"He went to the store,\" said the boy."
  • carlsmith
Nothing really. In Python, you can use either, but you must end the string with the same type of quotes as you start it with. It's useful because you'll often have quotes in strings. If you did name = 'O'Reilly' you'd get an error because the string 'O' is followed by some gibberish code, Reilly'. If you do name = "O'Reilly" everything is fine. You can use single quotes when you've got double quotes in a string. quote = 'He replies, "We're an autonomous workers collective".' If you want your string to span multiple lines, or if it contains both single and double quotes, you can use 'triple quotes', three single or three double quotes to open and three more of the same to close. both = ''' O'Reilly says "Hello" ''' long = ''' One line of text another one '''
  • carlsmith
Note: In triple quoted strings, newlines are preserved, even if they're blank lines. >>>print long One line of text another one >>> You've also got the escape characters. A backslashed character which has a special meaning. There's a few, but these are the common ones. \n = newline \t = tab \' = treat this single quote as a regular part of the string \" = same as above, but for a double quote \\ = same again, but for a backslash

Looking for something else?

Not the answer you are looking for? Search for more explanations.