Built-in Functions and Help

Overview

Teaching: 15 min
Exercises: 10 min
Questions
  • How can I find out what built-in functions do?

Objectives
  • Use help to display documentation for built-in functions.

A function may take zero or more arguments.

Commonly-used built-in function round and its arguments.

round(3.712)
4
round(3.712, 1)
3.7

Argument’s types matter.

round(3.712, 1.5)
TypeError                                 Traceback (most recent call last)
<ipython-input-43-95f04cdcdc64> in <module>
----> 1 round(3.712, 1.5)

TypeError: 'float' object cannot be interpreted as an integer

Use the built-in function help to get help for a function.

help(round)
Help on built-in function round in module builtins:

round(number, ndigits=None)
    Round a number to a given precision in decimal digits.
    
    The return value is an integer if ndigits is omitted or None.  Otherwise
    the return value has the same type as the number.  ndigits may be negative.

The Jupyter Notebook has two ways to get help.

Explore the Python docs!

The official Python documentation is arguably the most complete source of information about the language. It is available in different languages and contains a lot of useful resources. The Built-in Functions page contains a catalogue of all of these functions, including the ones that we’ve covered in this lesson. Some of these are more advanced and unnecessary at the moment, but others are very simple and useful.

Key Points

  • Functions may only work for certain (combinations of) arguments.

  • Functions may have default values for some arguments.

  • Use the built-in function help to get help for a function.

  • The Jupyter Notebook has two ways to get help.