Difference between '?' and 'help()'

Question:

What is the difference between ‘?’ and ‘help()’ in Python Jupyter Notebooks. E.g.

import scipy
help(scipy)
?scipy
Asked By: shenflow

||

Answers:

In Python, the ? symbol is used to display the documentation string of an object, while the help() function is used to display the documentation for a module, function, or object.

Here is an example of how to use these two methods in Python:

>>> x = [1, 2, 3]

>>> x?
Type:        list
String form: [1, 2, 3]
Length:      3
Docstring:  
Built-in mutable sequence.

>>> help(list)
Help on class list in module builtins:

class list(object)
    list() -> new empty list
    list(iterable) -> new list initialized from iterable's items
    
    Methods defined here:
    
    __add__(self, value, /)
        Return self+value.
    
    __contains__(self, key, /)
        Return key in self.
    
    __delitem__(self, key, /)
        Delete self[key].
   
Answered By: user2804447

Documentations are always a good place to start. 🙂

So, ? which is a magic, is equivalent to %pinfo as specified in the IPython docs.

Whereas help() is a built-in Python function that returns the documentation associated with a Python Object.

#p.s. Jupyter uses an IPython (or Interactive Python) kernel, which supports the magics.

Answered By: mrNobody
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.