diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst index 015231d9cff225..8f4bbe87443c82 100644 --- a/Doc/library/functions.rst +++ b/Doc/library/functions.rst @@ -1297,10 +1297,10 @@ are always available. They are listed here in alphabetical order. arguments starting at ``0``). -.. function:: round(number[, ndigits]) +.. function:: round(number, ndigits=None) Return *number* rounded to *ndigits* precision after the decimal - point. If *ndigits* is omitted or is ``None``, it returns the + point. If *ndigits* is omitted or ``None``, it returns the nearest integer to its input. For the built-in types supporting :func:`round`, values are rounded to the @@ -1308,11 +1308,12 @@ are always available. They are listed here in alphabetical order. equally close, rounding is done toward the even choice (so, for example, both ``round(0.5)`` and ``round(-0.5)`` are ``0``, and ``round(1.5)`` is ``2``). Any integer value is valid for *ndigits* (positive, zero, or - negative). The return value is an integer if called with one argument, - otherwise of the same type as *number*. + negative). The return value is an integer if *ndigits* is omitted or is ``None``. + Otherwise the return value has the same type as *number*. - For a general Python object ``number``, ``round(number, ndigits)`` delegates to - ``number.__round__(ndigits)``. + For a general Python object, ``round(number)`` or ``round(number, None)`` + delegates to ``number.__round__()``, and ``round(number, ndigits)`` delegates + to ``number.__round__(ndigits)``. .. note:: diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index 5e1f1d3854fc67..6135e750c31944 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -2087,10 +2087,10 @@ builtin_round(PyObject *self, PyObject *args, PyObject *kwds) } PyDoc_STRVAR(round_doc, -"round(number[, ndigits]) -> number\n\ +"round(number, ndigits=None) -> number\n\ \n\ Round a number to a given precision in decimal digits (default 0 digits).\n\ -This returns an int when called with one argument, otherwise the\n\ +This returns an int when ndigits is omitted or is None, otherwise the\n\ same type as the number. ndigits may be negative.");