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
I don't quite understand what triple quotes are for in python.
I have watched this video so many times now and still cannot understand what triple quotes are for in python. The official Python Documentation says its for spanning across three lines for a string, but the video doesn't show that happen. HELP!!!
Please explain this python triple quotes in very easy language. I am just a beginner;
Triple quotes are for setting a string that spans multiple lines. It is also the convention for writing Docstrings (ignore this if you haven't covered Docstrings yet).
It's also noteworthy that a triple quote will ignore single quotes allowing you to add them for grammar purposes.
Here's a couple examples:
'Example of a single quote spanning multiple
lines. It doesn't work!'
""" Example of triple quotes spanning
Also not the use of "quotations"
without having weird formatting issues.
Francesc Box1,637 Points
As a complement to previous answer, it's handy when you want to work with a string that contains both single and double quotes at the same time. You will use triple quotes at the beginning and at the end of the string; then you are free to mix single and double quotes within the string.
>>> var = """ "I can't do it", he said. """
"I can't do it", she said.
Francesc Box1,637 Points
gender complaint code? :-) actually, copy/paste did not work, so I directly wrote the code on the window.
Rouillie Wilkerson10,419 Points
The triple quotes are like very specific instructions to keep the quotes within the string, in addition to the initial opening and closing quotes.
For instance. If I want to write: I stared at the evil bunny, "halt!" it hissed.
I would code it as follows: """I stared at the evil bunny, "halt!" it hissed."""
Then I hit return, an this is what I'd see: 'I stared at the evil bunny, "halt!" it hissed.'
Notice how the halt is still in proper quotes? The triple quotes, at the start and finish told the program to keep those quotes around the word halt.
Now, if you enter print(_) at the prompt, it'll print as follows:
I stared at the evil bunny, "halt!" it hissed.
Just as you intended! I hope this helps!