https://www.pythonmorsels.com/help-features/ Python Morsels * Articles * Screencasts * Exercises * Python Tips * Tools Python Pastebin Online Python REPL strptime undataclass Python Glossary * Python Jumpstart [ ] / * Sign Up * Sign In The features of Python's help() function Trey Hunner smiling in a t-shirt against a yellow wall Trey Hunner 10 min. read * Python 3.9--3.13 * March 3, 2025 Share Copied to clipboard. Python has a built-in help function for getting help... but what can do with help? The help function can be used to lookup documentation for: 1. Functions 2. Modules 3. Any Object 4. Symbols 5. Keywords 6. Topics Let's take a look at all 6 uses of help. We'll start with the most common 3 uses: functions, modules, and all other objects. Passing objects to help I almost always use the help function by passing an object to it: either a function, module, class, or class instance. Passing a function object (yes functions are objects in Python) to help(...) will show the docstring for that function: >>> help(print) Help on built-in function print in module builtins: print(*args, sep=' ', end='\n', file=None, flush=False) Prints the values to a stream, or to sys.stdout by default. sep string inserted between values, default a space. end string appended after the last value, default a newline. file a file-like object (stream); defaults to the current sys.stdout. flush whether to forcibly flush the stream. Passing a class or an instance of a class will show the docstring for that class as well as the documentation for each method in the class: >>> numbers = [2, 1, 3, 4] >>> help(numbers) Help on list object: class list(object) | list(iterable=(), /) | | Built-in mutable sequence. | | If no argument is given, the constructor creates a new empty list. | The argument must be an iterable if specified. | | Methods defined here: | | __add__(self, value, /) | Return self+value. | | __contains__(self, key, /) | Return bool(key in self). | ... [Many more methods shown after this] Passing a module object will show the documentation for everything within the module: >>> import math >>> help(math) Help on module math: NAME math MODULE REFERENCE https://docs.python.org/3.13/library/math.html The following documentation is automatically generated from the Python source files. It may be incomplete, incorrect or include features that are considered implementation detail and may vary between Python implementations. When in doubt, consult the module reference at the location listed above. DESCRIPTION This module provides access to the mathematical functions defined by the C standard. FUNCTIONS acos(x, /) Return the arc cosine (measured in radians) of x. The result is between 0 and pi. acosh(x, /) Return the inverse hyperbolic cosine of x. ... [Many more functions shown after this, as well as data attributes] You can also pass method objects (methods are just functions attached to classes) or functions from a module into help: >>> help(numbers.pop) Help on built-in function pop: pop(index=-1, /) method of builtins.list instance Remove and return item at index (default last). Raises IndexError if list is empty or index is out of range. >>> help(math.sqrt) Help on built-in function sqrt in module math: sqrt(x, /) Return the square root of x. There are other ways to use the help function, but before we dive into those I'd like to address the *, and / symbols shown in the output above. Aside: keyboard shortcuts Once you're in help, how do you move around? Also, how do you exit help? The help function supports different keyboard shortcuts on different platforms, which is a bit unfortunate. On Windows, the Python help function usually uses the more command. On Linux and Mac, it uses the less command. The most useful keyboard shortcuts to know for help on Linux and Mac are: * Down or j to scroll down one line at a time * Up or k to scroll up one line at a time * Ctrl-D to scroll down one half screen * Ctrl-U to scroll up one half screen * / to search downward within the current help page * ? to search upward within the current help page * q to quit help The most useful keyboard shortcuts to know for help on Windows are: * Enter to navigate down one line at a time * Space to navigate down one half screen * q to quit The more program or less program that Python uses (depending on your operating system) are called "pagers". If you happen to have a fancier pager program installed, you can set your PAGER or MANPAGER environment variable to customize which pager program is used. Getting help on strings The help function will accept any object and return help on that object. But the help function also accepts strings: >>> help("math.prod") Help on built-in function prod in math: math.prod = prod(iterable, /, *, start=1) Calculate the product of all the elements in the input iterable. The default start value for the product is 1. When the iterable is empty, return the start value. This function is intended specifically for use with numeric values and may reject non-numeric types. This is handy for getting help on a utility that you haven't yet imported into your Python REPL. But this also means we can't pass a string to help and expect to see help on the str type: >>> name = "Trey" >>> help(name) No Python documentation found for 'Trey'. Use help() to get the interactive help utility. Use help(str) for help on the str class. To get help on strings, you'll need to pass in the string class, not a string instance: >>> help(str) Help on class str in module builtins: class str(object) | str(object='') -> str | str(bytes_or_buffer[, encoding[, errors]]) -> str | | Create a new string object from the given object. If encoding or | errors is specified, then the object must expose a data buffer | that will be decoded using the given encoding and error handler. | Otherwise, returns the result of object.__str__() (if defined) | or repr(object). | encoding defaults to 'utf-8'. | errors defaults to 'strict'. | | Methods defined here: | | __add__(self, value, /) | Return self+value. | ... [Many more methods shown after this] Looking up symbols, keywords, and topics The strings passed to help don't necessarily need to represent the path to a Python object. The help function also accepts strings representing symbols, keywords, and topics. Looking up help on symbols Since symbols are not objects in Python, they can't be passed as an argument to help: >>> help(**) File "", line 1 help(**) ^ SyntaxError: invalid syntax To lookup help on a symbol, you can pass a string to the help function. For example, here we're looking up what the ** operator does: >>> help("**") The power operator ****************** The power operator binds more tightly than unary operators on its left; it binds less tightly than unary operators on its right. The syntax is: power ::= (await_expr | primary) ["**" u_expr] Thus, in an unparenthesized sequence of power and unary operators, the operators are evaluated from right to left (this does not constrain the evaluation order for the operands): "-1**2" results in "-1". The power operator has the same semantics as the built-in "pow()" function, when called with two arguments: it yields its left argument raised to the power of its right argument. The numeric arguments are first converted to a common type, and the result is of that type. For int operands, the result has the same type as the operands unless the second argument is negative; in that case, all arguments are converted to float and a float result is delivered. For example, "10**2" returns "100", but "10**-2" returns "0.01". Raising "0.0" to a negative power results in a "ZeroDivisionError". Raising a negative number to a fractional power results in a "complex" number. (In earlier versions it raised a "ValueError".) This operation can be customized using the special "__pow__()" and "__rpow__()" methods. Related help topics: EXPRESSIONS, OPERATORS Looking up help on keywords Keywords are words that can't be used as valid Python variable names. For example, class, if, for, and return are keywords used within Python syntax. Attempting to pass those keywords to help would result in a SyntaxError: >>> help(return) File "", line 1 help(return) ^^^^^^ SyntaxError: invalid syntax Like symbols, you can get help on a keyword by passing it to the help function as a string: >>> help("if") The "if" statement ****************** The "if" statement is used for conditional execution: if_stmt ::= "if" assignment_expression ":" suite ("elif" assignment_expression ":" suite)* ["else" ":" suite] It selects exactly one of the suites by evaluating the expressions one by one until one is found to be true (see section Boolean operations for the definition of true and false); then that suite is executed (and no other part of the "if" statement is executed or evaluated). If all expressions are false, the suite of the "else" clause, if present, is executed. Related help topics: TRUTHVALUE Looking up help on topics You may have noticed "related help topics" listed at the bottom of some help documents. To get help on one of those topics, pass one of them to the help function: >>> help("TRUTHVALUE") Truth Value Testing ******************* Any object can be tested for truth value, for use in an "if" or "while" condition or as operand of the Boolean operations below. By default, an object is considered true unless its class defines either a "__bool__()" method that returns "False" or a "__len__()" method that returns zero, when called with the object. [1] Here are most of the built-in objects considered false: * constants defined to be false: "None" and "False" * zero of any numeric type: "0", "0.0", "0j", "Decimal(0)", "Fraction(0, 1)" * empty sequences and collections: "''", "()", "[]", "{}", "set()", "range(0)" Operations and built-in functions that have a Boolean result always return "0" or "False" for false and "1" or "True" for true, unless otherwise stated. (Important exception: the Boolean operations "or" and "and" always return one of their operands.) Related help topics: if, while, and, or, not, BASICMETHODS Topics are always spelled in ALLUPPERCASE to distinguish them from keywords, symbols, etc. Meta-help Want to know what topics there are that you can ask for help about? Ask for help on "topics": >>> help("topics") Here is a list of available topics. Enter any topic name to get more help. ASSERTION DELETION LOOPING SHIFTING ASSIGNMENT DICTIONARIES MAPPINGMETHODS SLICINGS ATTRIBUTEMETHODS DICTIONARYLITERALS MAPPINGS SPECIALATTRIBUTES ATTRIBUTES DYNAMICFEATURES METHODS SPECIALIDENTIFIERS AUGMENTEDASSIGNMENT ELLIPSIS MODULES SPECIALMETHODS BASICMETHODS EXCEPTIONS NAMESPACES STRINGMETHODS BINARY EXECUTION NONE STRINGS BITWISE EXPRESSIONS NUMBERMETHODS SUBSCRIPTS BOOLEAN FLOAT NUMBERS TRACEBACKS CALLABLEMETHODS FORMATTING OBJECTS TRUTHVALUE CALLS FRAMEOBJECTS OPERATORS TUPLELITERALS CLASSES FRAMES PACKAGES TUPLES CODEOBJECTS FUNCTIONS POWER TYPEOBJECTS COMPARISON IDENTIFIERS PRECEDENCE TYPES COMPLEX IMPORTING PRIVATENAMES UNARY CONDITIONAL INTEGER RETURNING UNICODE CONTEXTMANAGERS LISTLITERALS SCOPING CONVERSIONS LISTS SEQUENCEMETHODS DEBUGGING LITERALS SEQUENCES To see what symbols you can ask for help on, pass "symbols" to help: >>> help("symbols") Here is a list of the punctuation symbols which Python assigns special meaning to. Enter any symbol to get more help. != + <= __ " += <> ` """ , == b" % - > b' %= -= >= f" & . >> f' &= ... >>= j ' / @ r" ''' // J r' ( //= [ u" ) /= \ u' * : ] | ** < ^ |= **= << ^= ~ *= <<= _ The same thing works with "keywords" as well: >>> help("keywords") Here is a list of the Python keywords. Enter any keyword to get more help. False class from or None continue global pass True def if raise and del import return as elif in try assert else is while async except lambda with await finally nonlocal yield break for not If you ask for help of "modules" you'll also see a list of all installed modules which you can ask for help on: >>> help("modules") Python imports every module it can find in order to gather that information, so the first time help("modules") is run within a Python process, it usually takes a second for Python to discover and import all the modules. The "help utility" Not sure what you want help on? If you call the help function without any arguments, you'll enter the "help utility". >>> help() Welcome to Python 3.13's help utility! If this is your first time using Python, you should definitely check out the tutorial at https://docs.python.org/3.13/tutorial/. Enter the name of any module, keyword, or topic to get help on writing Python programs and using Python modules. To get a list of available modules, keywords, symbols, or topics, enter "modules", "keywords", "symbols", or "topics". Each module also comes with a one-line summary of what it does; to list the modules whose name or summary contain a given string such as "spam", enter "modules spam". To quit this help utility and return to the interpreter, enter "q", "quit" or "exit". help> Note: as of Python 3.13, you can type help without any parentheses to launch the same utility. From the help utility, you can enter the name of the thing you would like to get help on. Any string that the help function accepts can be provided at this help> prompt to see documentation for it. You'll often find that the string doesn't have help. For example, functions doesn't have help: help> functions No Python documentation found for 'functions'. Use help() to get the interactive help utility. Use help(str) for help on the str class. If you type help from the help utility you can see the initial prompt again, which notes that modules, keywords, symbols, and topics are the top-level categories that you can use to discover what possible strings help will accept: help> help Welcome to Python 3.13's help utility! If this is your first time using Python, you should definitely check out the tutorial at https://docs.python.org/3.13/tutorial/. Enter the name of any module, keyword, or topic to get help on writing Python programs and using Python modules. To get a list of available modules, keywords, symbols, or topics, enter "modules", "keywords", "symbols", or "topics". Each module also comes with a one-line summary of what it does; to list the modules whose name or summary contain a given string such as "spam", enter "modules spam". To quit this help utility and return to the interpreter, enter "q", "quit" or "exit". Stuck without Internet? You've still got help! Why use the help function when we have a search engine? Well, if you're stuck without Internet for a few hours the help function can be very handy. Also, if you find yourself in a Python REPL or a PDB session and you're wondering how a particular object works, help can be very handy for introspecting an object. You may also want to look into the type, dir, and vars functions for introspecting Python objects. For more on how decipher the various symbols you'll see used in function definitions within help output, see understanding help in Python. A Python tip every week Need to fill-in gaps in your Python skills? Sign up for my Python newsletter where I share one of my favorite Python tips every week. [ ] Website [ ] Get weekly Python tips | A Python Tip Every Week Python Morsels logo: an adorable green snake wrapped around a large chocolate chip cookie with a bite taken out of it (presumably the snake has taken a bite of this cookie) Need to fill-in gaps in your Python skills? I send weekly emails designed to do just that. [ ] Website [ ] [Sign up for weekly Python tips] Table of Contents * + Sign in to record your progress Sign in to your Python Morsels account to track your progress. Don't have an account yet? Sign up here. Python Morsels logo: an adorable green snake wrapped around a large chocolate chip cookie with a bite taken out of it (presumably the snake has taken a bite of this cookie) (c) 2025 New User * Testimonials * Team Plans * Pricing * Redeem Code About * Feature History * Privacy Policy * About Us Quick Resources * Python Terminology * Python Resources * Python Training * Python Team Training * Trey's Blog Learn a Python Tip every week Join my newsletter to fill-in gaps in your Python skills. Every Wednesday, I share a Python tip. [ ] Sign up Website [ ]