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 trialAnthony Lopez
963 PointsTriple quotation marks?
In the application video for lists the instructor uses triple quotation marks when trying to print. Why exactly?
print(""" Enter 'DONE' to stop adding items. Enter 'HELP' for this help. """)
Also when he was creating a definition he left the parameter blank. What is the purpose of that, and what is the purpose of defining the parameter?
def show_help():
Thank you!
1 Answer
John Lack-Wilson
8,181 PointsThe triple quotation is a nice way to be able to include other types of quotation within your string without having to use escape characters. For example:
print("He said \"my name's John\"")
That example requires escape characters \" to use double quote marks. Or you can imagine even more complex examples using multiple double quotations and/or single quotations, where the whole string will look very messy with many escapes everywhere.
Triple quotations don't require the escape characters because you shouldn't ever need to use triple quotes within the string. Essentially, it makes the string more readable.
RE: Also when he was creating a definition he left the parameter blank. What is the purpose of that, and what is the purpose of defining the parameter?
Some functions don't require a parameter, some do. It depends on what the function does. Here's a couple of example to highlight this:
def hello():
print("Hello!")
def hello(name):
print("Hello, " + name)
The first hello() function cannot customise a greeting, it can only say 'Hello', or maybe use a specific name - which of course won't work for everyone. Whereas the second example can give a customised greeting, using the name argument that gets passed to it.
Anthony Lopez
963 PointsAnthony Lopez
963 PointsThanks John!