# How to print the docstring of the  \`input\`  function?

**URL:** <https://discuss.python.org/t/how-to-print-the-docstring-of-the-input-function/3486>\
**Category:** Python Help\
**Created:** [February 26, 2020, 6:41am UTC](https://discuss.python.org/t/how-to-print-the-docstring-of-the-input-function/3486 "2020-02-26T06:41:27Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![David\_Billa](https://avatars.discourse-cdn.com/v4/letter/d/e19adc/32.png) [@David\_Billa](https://discuss.python.org/u/David_Billa)\
**Post date:** [February 26, 2020, 6:41am UTC](https://discuss.python.org/t/how-to-print-the-docstring-of-the-input-function/3486/1 "2020-02-26T06:41:27Z")

</div>

Write a python script to print the docstring(documentation string) of the `input` function in Python 3?

I’m new to Python and unable to find the answers for this question.

---

<div class="post-metadata">

**Author:** ![steven.daprano](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/steven.daprano/32/1083_2.png) [@steven.daprano](https://discuss.python.org/u/steven.daprano)\
**Post date:** [February 26, 2020, 9:31am UTC](https://discuss.python.org/t/how-to-print-the-docstring-of-the-input-function/3486/2 "2020-02-26T09:31:24Z")

</div>

Hi David, and welcome.

This sounds like a homework exercise. What have you tried?

You want to print the docstring of the `input` function. Here are all  
the individual pieces you need to solve the problem, without giving you  
the exact answer.

You want to get access to the `input` function without calling the  
function. Just leave off the parentheses!

```
answer = input("question?") # calls the function

obj = input # doesn't call the function

```

You want to see the doc string of an object, if it has one:

```
# Note that this is *two* leading and trailing underscores
# not just one
docs = myobject. __doc__

```

You want to see the doc string of the builtin `len` function:

```
docs = len. __doc__ # don't call the function!

```

You want to print something:

```
print(something)

```

Put all the pieces together, and you will be able to print the `input`  
function’s doc string.

If you can’t work it out, show what you tried, and what result you got.

---

<div class="post-metadata">

**Author:** ![David\_Billa](https://avatars.discourse-cdn.com/v4/letter/d/e19adc/32.png) [@David\_Billa](https://discuss.python.org/u/David_Billa)\
**Post date:** [February 26, 2020, 11:13am UTC](https://discuss.python.org/t/how-to-print-the-docstring-of-the-input-function/3486/3 "2020-02-26T11:13:11Z")

</div>

Thanks for the reply. You meant to say that I have combine all the pieces to make it right?

---

<div class="post-metadata">

**Author:** ![David\_Billa](https://avatars.discourse-cdn.com/v4/letter/d/e19adc/32.png) [@David\_Billa](https://discuss.python.org/u/David_Billa)\
**Post date:** [February 26, 2020, 3:05pm UTC](https://discuss.python.org/t/how-to-print-the-docstring-of-the-input-function/3486/4 "2020-02-26T15:05:00Z")

</div>

I tried as follows but ended up with name error:(. Could you please correct me?

answer = input(“question?”) # calls the function  
obj = input # doesn’t call the function  
docs = obj. **doc**  
docs = len. **doc**  
print(something)

ERROR:

python3 app.py | tee output.txt  
question?python3 app.py | tee output.txt  
Traceback (most recent call last):  
File “app.py”, line 3, in   
docs = myobject. **doc**  
NameError: name ‘myobject’ is not defined  
 vim app.py python3 app.py | tee output.txt  
question?

---

<div class="post-metadata">

**Author:** ![suman](https://avatars.discourse-cdn.com/v4/letter/s/5fc32e/32.png) [@suman](https://discuss.python.org/u/suman)\
**Post date:** [April 19, 2020, 2:25pm UTC](https://discuss.python.org/t/how-to-print-the-docstring-of-the-input-function/3486/5 "2020-04-19T14:25:52Z")

</div>

I think there are two options:

1. just use print(input. **doc** )
2. or use help(input)

Anyone should work.

---

<div class="post-metadata">

**Author:** ![Devil](https://avatars.discourse-cdn.com/v4/letter/d/3bc359/32.png) [@Devil](https://discuss.python.org/u/Devil)\
**Post date:** [April 27, 2020, 6:34am UTC](https://discuss.python.org/t/how-to-print-the-docstring-of-the-input-function/3486/6 "2020-04-27T06:34:40Z")

</div>

u can try in this way  
def input():  
‘’‘this is doc string’’’  
return None  
print(input. **doc** )  
help(input)  
you got your ans. this code work 100%

---

<div class="post-metadata">

**Author:** ![TusharThote](https://avatars.discourse-cdn.com/v4/letter/t/13edae/32.png) [@TusharThote](https://discuss.python.org/u/TusharThote)\
**Post date:** [May 5, 2020, 7:44am UTC](https://discuss.python.org/t/how-to-print-the-docstring-of-the-input-function/3486/7 "2020-05-05T07:44:10Z")

</div>

You can use below.

def input():  
‘’‘Hello’’’  
print(help(input)) or help(input)

---

<div class="post-metadata">

**Author:** ![Andres\_Forero](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/andres_forero/32/2452_2.png) [@Andres\_Forero](https://discuss.python.org/u/Andres_Forero)\
**Post date:** [July 6, 2020, 5:24pm UTC](https://discuss.python.org/t/how-to-print-the-docstring-of-the-input-function/3486/8 "2020-07-06T17:24:12Z")

</div>

i have error en ““this is doc string””  
you help me!

---

<div class="post-metadata">

**Author:** ![steven.daprano](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/steven.daprano/32/1083_2.png) [@steven.daprano](https://discuss.python.org/u/steven.daprano)\
**Post date:** [July 7, 2020, 1:51am UTC](https://discuss.python.org/t/how-to-print-the-docstring-of-the-input-function/3486/9 "2020-07-07T01:51:40Z")

</div>

It should be either _one_ set of quotes or _three_, but not two:

```
# Okay
"this is a one-line doc string"

# better
"""this is a doc string,
It can have more than one line.
"""

# Invalid syntax.
"" two quotes doesn't work ""
```
