Aditya Raj Bhatt wrote: > I always do single line comments with # but just for the sake of it I > tried it with ''' ''' and it gives me a syntax error. > > In both the interpreter, and the source code text file, doing - > > a = 5 '''a comment''' > > results in a syntax error, with the very last quote at the end of the > line highlighted in red. Of course, if I do - > > a = 5 #'''a comment''' <zip> > Can someone also provide a sort of a 'guide' to triple-quoted comments > in general?
A triple ' or " string is a Python string, allowing line-return in string. If it is in an expression (like a = 5 '''a comment'''), then it must be a valid expression (and here it is not). You can have an expression alone, with no stored result (ie. no assignment to a name), and this is how are used triple quoted strings as comments. a = 5 """a comment""" Take care of indent: def f(x): a = 5 """an correctly indented expression to be inside the function""" return a * x A+ Laurent. -- https://mail.python.org/mailman/listinfo/python-list