0

How can I quickly check what are the possible inputs to a specific function? For example, I want to plot a histogram for a data frame: df.hist(). I know I can change the bin size, so I know probably there is a way to give the desired bin size as an input to the hist() function. If instead of bins = 10 I use df.hist(bin = 10), Python obviously gives me an error and says hist does not have property bin.

I wonder how I can quickly check what are the possible inputs to a function.

3
  • 8
    Generally, you need to read the documentation. Commented Dec 2, 2019 at 17:38
  • 2
    An editor or IDE with decent completion can help too. Commented Dec 2, 2019 at 17:38
  • I know the best way is always reading the documentation but sometimes, like the example I described above, you have a good guess of what the input should look like and I was looking for a way to verify quickly. Commented Dec 2, 2019 at 18:12

4 Answers 4

3

Since your question tag contains jupyter notebook I am assuming you are trying on it. So in jupyter notebook 2.0 Shift+Tab would give you function arguments.

Sign up to request clarification or add additional context in comments.

Comments

2

One way is to see if there is documentation on the function itself:

from pandas import DataFrame as DF
help(DF.hist)

Alternatively, if you are inside IPython, using DF.hist? will work as well.

Comments

0

You can use the help function:

help(df.hist)

Also:

df.hist? # in ipython only

The possible arguments will print into the console.

1 Comment

The ? suffix syntax isn't part of Python. It's something that iPython adds.
0

You can use the inspect module

def f(x, y):
    return x + y

print(inspect.signature(f))

See the documentation of the module for details regarding the returned type.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.