May-06-2020, 04:05 PM
Oneliner start with
How to make comment block?
#
How to make comment block?
Multiline comments
|
May-06-2020, 04:05 PM
Oneliner start with
# How to make comment block?
May-06-2020, 04:18 PM
Python does not have a separate syntax for multi line comments. You could use
# for each line to be commented
May-06-2020, 04:46 PM
Multiline strings are commonly used to get around the limitation. The string definition needs to be properly indented. So,
""" This is an example of a multi line comment using a multi line string """ def foobar() : for idx in range (15) : print(idx) """ Done with the loop What to do next? Probably just return """ return foobar()This is also how docstrings are defined. def fna(alpha, beta) : """ This function does nothing useful. alpha should be a number beta should be a number fna returns the sum of the numbers """ return alpha+beta print(fna.__doc__)
May-06-2020, 06:01 PM
Also
help() works if have docstrings in functions or classes.>>> help(fna) Help on function fna in module __main__: fna(alpha, beta) This function does nothing useful. alpha should be a number beta should be a number fna returns the sum of the numbers
May-07-2020, 09:58 AM
(This post was last modified: May-07-2020, 09:58 AM by pyzyx3qwerty.)
Comment block can be done like this :
""" This is a comment. This is another comment. This is the last comment. """ # The above lines were a comment block, whereas this is only a one-line comment
pyzyx3qwerty
"The greatest glory in living lies not in never falling, but in rising every time we fall." - Nelson Mandela Need help on the forum? Visit help @ python forum For learning more and more about python, visit Python docs
May-07-2020, 12:38 PM
With how syntax highlighting works I prefer using # for all comments and """ for doc strings and multi-line strings. But I hardly ever use multi-line comments that I don't want to be part of the documentation.
May-07-2020, 08:14 PM
OK Thank you everyone for your help.
|
|