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 trialAlan Temirov
Courses Plus Student 762 PointsQuote marks
Is there a way where in a text that I want to print out I can use double quote marks and combinate them with double quote marks that comprise the whole text in my argument, or I can use only different types of quote marks in my text and in comprising it at the same time?
2 Answers
Jeff Muday
Treehouse Moderator 28,720 PointsYou can enclose double-quoted strings in single quotes -- here, the title "The Real Slim Shady" is inside a single-quoted string.
x = '"The Real Slim Shady" is a song by American rapper Eminem.'
You can use a backslash quoting character as well. It might be confusing, but it works.
y = "Another well-known rapper is \"Lil' John\"."
A third method is a multi-line string that must be enclosed in either three single-quotes or three double-quotes. You can possibly put the string on a single line of code. But usually, a string like this allows the programmer to take advantage of embedded linebreaks.
x = '"The Real Slim Shady" is a song by American rapper Eminem.'
y = "Another well-known rapper is \"Lil' John\"."
print(x)
print(y)
long_string = """
Frank Thomas, retired baseball player, is nicknamed "The Big Hurt"
"""
print(long_string)
The output looks like this:
"The Real Slim Shady" is a song by American rapper Eminem.
Another well-known rapper is "Lil' John".
Frank Thomas, retired baseball player, is nicknamed "The Big Hurt"
Alan Temirov
Courses Plus Student 762 PointsThank you,Jeff,awesome answer,that truly has helped me to solve this enigma!