[Tutor] comments in python
Michael Janssen
Janssen@rz.uni-frankfurt.de
Thu Jan 9 18:26:06 2003
On Thu, 9 Jan 2003, john gennard wrote:
> a. #blah blah blah
> This of course is no problem, but then I've seen:-
>
> b. """
> blah blah blah
> """
> and also:-
>
> c. ''' blah blah blah '''
>
>
> b. and c. only seem to be used in the 'meat' of the programs,
> usually after the exhortation 'do not alter below here'
"Tripple quotes" can be used to write strings over several lines:
multiline = "this
is broken"
multiline2 = """this
not"""
please take a look at section 3.1.2 of the Python Tutorial for the details
of this usage of tripple quotes.
Those "Tripple quotes"-Strings are also a way to provide inline
documentation and are therefore called docstrings.
E.g. you can use a docstrings to describe a function:
def func():
"""Return zero"""
return 0
When you type this function into the interpreter and run the command
help(func) you will get the docstring as a explanation. Docstrings doesn't
do any programm-logic, but they are part of the programm: inline
documentation, as already said. Docstrings are described here:
http://www.python.org/doc/essays/styleguide.html
Michael
PS: b) and c) are functional equivalent. But nobody uses "single tripple
quotes": ugly.
>
> I can find in O'Reilly reference to the use of triple quotes under
> 'strings' but what I see in the programs appears to be quite
> different to this.
>
> Will someone say if I'm just being thick? Perhaps I don't understand
> what a 'string' is in plain language!
>
> Any help will be much appreciated.
>
> Regards, John.
>
>
> _______________________________________________
> Tutor maillist - Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>