+ 3

Can docstring contain multiple lines of text in Python?

Hey!!! I am learning python, in that I want to ask about docstrings - Can docstring contain multiple lines of text in Python? Thank you!!!!!:-)

2nd Jul 2020, 9:35 AM
Aveer Dhare
Aveer Dhare - avatar
7 ответов
+ 3
Thank you so much my friends.............
2nd Jul 2020, 4:35 PM
Aveer Dhare
Aveer Dhare - avatar
+ 7
Yes, of course, Docstrings act as multiline comments in python that are ignored while running the program. Because "#" supports only 1 line comments
2nd Jul 2020, 9:50 AM
Arctic Fox
Arctic Fox - avatar
+ 7
𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥, your definition of docstring is incorrect, Kiibo. As Code Crasher pointed out, a doc string is a specific documentation tool. If you start a module, class, function or method with a string literal - ANY string literal - it will be stored in the attribute __doc__ of that m, c, f or m. Instead of using help, pydoc etc. you can also write: print(f.__doc__) This... '''Hello Kiibo''" ... is just one way to write a string. It is not different to any other string literal you write.
2nd Jul 2020, 1:48 PM
HonFu
HonFu - avatar
+ 5
Kiibo, do you know what a docstring is? It is what will be printed if you use the help function on your function, module, class or whatever. def f(): 'Hello World' help(f) # Output: Hello World For this to work, the string has to be at the top.
2nd Jul 2020, 1:26 PM
HonFu
HonFu - avatar
+ 4
The only two things a docstring has to do are: 1.) be a string, and 2.) be at the beginning of the function.
2nd Jul 2020, 10:06 AM
HonFu
HonFu - avatar
+ 3
Wrong: def f(): kiibo = "I'm wrong here" 'docstring' Correct: def f(): 'docstring' kiibo = 'attaboy'
2nd Jul 2020, 10:56 AM
HonFu
HonFu - avatar
0
Can a docstring contain multiple lines of text? docstring can also overlap to multiple lines, just like multi line comments. docstring with help of triple-quotation mark. answer: yes
17th Dec 2020, 8:31 AM
umesha ramanayake
umesha ramanayake - avatar