1) b. Multi-line comments Examples




Lou Pylot has gotten her first python code ever from Pepyto and all she wants is to leave a comment for Pepyto within his code but she is afraid she will mess with his code. Help her write ‘pithy’ comments that take one line. Comments in a code convey a message for other developers that read it but are completely ignored by the python interpreter.

1
2
3
4
5
6
Original code:
print(Hi everyone! I'm Pepyto)

print "How are you doing?"

print("I'
m writing Python code!!!




Lou now realized that she needs to leave longer messages on the code. But how can she break the line …and still continue with the comment? Help Lou write a comment that extends over two lines or more!




Lou scrambled upon a function from Pepyto’s program that does not know how to use it. Help Pepyto write a ‘doc string’, that is a multi-line comment (documentation) right after the definition of a function, that explains what the function is, what arguments it takes and what it does.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
def doc_string_inside_a_function():
  """Don't worry about what is meant by a function. We will cover it quite soon.
 
  For now notice how all these comments are enclosed within triple quotes.
  When you do this immediately inside a function or class it's called
  "Doc strings"!
  Doc strings typically provide more information about the function or class.
 
  These comments are special because these can be printed. For example:
 
  help <name of the function/class>
 
  This will print the docstring contained within that function/class
  """

 
 
print(help(doc_string_inside_a_function))




Lou wants to understand better the code she got from Pepyto. How can she print the string documentation of each function of the code? Experiment with the method help(). What do you see?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
def doc_string_inside_a_function():
  """Don't worry about what is meant by a function. We will cover it quite soon.
 
  For now notice how all these comments are enclosed within triple quotes.
  When you do this immediately inside a function or class it's called
  "Doc strings"!
  Doc strings typically provide more information about the function or class.
 
  These comments are special because these can be printed. For example:
 
  help <name of the function/class>
 
  This will print the docstring contained within that function/class
  """

 
# The following line will print the above docstring
print(help(doc_string_inside_a_function))



In the next chapter you will learn some basics about how to format the output while printing.