+ 9
difference b/w using' # ' and using ' """ '
what is the difference between using # and/or """ for commenting text out
3 Answers
+ 5
You can use """ to hide text from the interpreter, but """ doesn't actually create a comment. It creates a string. So the following line will not occupy any memory in the running program
# this is a comment and is ignored by python
while the following will occupy space in the program's memory, even if python never does anything with it:
"""
This is a string. I can use it like a comment, to contain information about the program, but it actually
consumes memory.
"""
When a """ string immediately follows the line that defines a function, that string is attached to the function object as its __doc__ attribute. So you can get often information about functions in code loaded into the interpreter by examining the function's __doc__ attribute. For example:
def fibonacci():
"""
This function computes the Fibonacci sequence.
"""
....
print(fibonacci.__doc__)
would output "This function computes the Fibonacci sequence."
+ 3
đ˛đđ I just got down vote for not knowing doc attribute.
it's hilarious đđ˛đ
+ 1
i didnt knew about that _doc_ attribute.
thanks bro.