+ 9

difference b/w using' # ' and using ' """ '

what is the difference between using # and/or """ for commenting text out

25th Mar 2017, 7:41 PM
Code Ninja
Code Ninja - avatar
3 Antworten
+ 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."
26th Mar 2017, 12:08 AM
tom barron
+ 3
😲😂😝 I just got down vote for not knowing doc attribute. it's hilarious 😕😲😝
8th Jul 2017, 3:32 PM
Code Ninja
Code Ninja - avatar
+ 1
i didnt knew about that _doc_ attribute. thanks bro.
29th Jun 2017, 5:00 AM
Code Ninja
Code Ninja - avatar