Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Write Better Python Cleaner Code Docstrings

Mateo Rial
Mateo Rial
3,694 Points

where is the error I cant show the docstring at the console

def does_s(arg):
    """Does something depending of the type.
    if arg is a stings, return arg * 3;
    if arg is an int or float, returns arg + 10
    """
    if isinstance(arg, (int, float)):
        return arg + 10
    elif isinstance(arg, str):
        return str * 3
    else:
        raise TypeError("does_s only takes strings, ints and floats")

at the console:

python

import docstrings

help(docstrings, does_s)

(output: "does_s is not defined")

Can you please provide Code Formatting so that it is easier to read your code?

All you need to do is stick ```python and ``` around your code like this:

```python

# Your code goes here

```

Will turn into:

# Your code goes here

Thanks! ~Alex

2 Answers

You have to refer to your does_s properly.

This means you have to tell Python the the does_s function is from docstrings.

You did this by using a comma, try using a period instead :)

Instead of typing this in the Python shell:

help(docstrings, does_s)

Try this:

help(docstrings.does_s)

Good luck! ~alex

Mateo Rial
Mateo Rial
3,694 Points

how stupid I didnt realised ... thanks alex!! now its easier to read

Thank you! Now I can help you fix you solution.