Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
be7311b
document that float() accepts bytes-like objects
Qanty228 Aug 10, 2026
083e890
📜🤖 Added by blurb_it.
blurb-it[bot] Aug 10, 2026
8923c21
📜🤖 Added by blurb_it.
blurb-it[bot] Aug 10, 2026
f0ce4e3
📜🤖 Added by blurb_it.
blurb-it[bot] Aug 10, 2026
7b01c73
Delete duplicate news entry
Qanty228 Aug 11, 2026
41deea8
Delete duplicate news entry
Qanty228 Aug 11, 2026
900dce0
document that float() accepts bytes-like objects (rst version)
Qanty228 Aug 11, 2026
8e56647
Merge branch 'python:main' into float-doc-fix
Qanty228 Aug 11, 2026
1e57613
document that float() accepts bytes-like objects (rst version)
Qanty228 Aug 11, 2026
ea75d71
functions.rst trailing whitespace fix
Qanty228 Aug 11, 2026
4844e94
import array functions.rst float fix
Qanty228 Aug 11, 2026
e09a351
add more examples of float conversions
Qanty228 Aug 11, 2026
854a77e
Delete NEWS entry
Qanty228 Aug 11, 2026
4a60f4e
Merge branch 'main' into float-doc-fix
Qanty228 Aug 11, 2026
35f3fd1
Update float doc to be more readable in functions.rst
Qanty228 Aug 21, 2026
e1b6fdc
Grammar fix in Doc/library/functions.rst
Qanty228 Aug 21, 2026
2143a0e
Reduce amount of examples of the same type in Doc/library/functions.rst
Qanty228 Aug 21, 2026
3f54b6e
Update Doc/library/functions.rst
Qanty228 Aug 22, 2026
1bf09dd
Update Doc/library/functions.rst
Qanty228 Aug 22, 2026
92bef32
Merge remote-tracking branch 'origin/main' into float-doc-fix
Qanty228 Sep 21, 2026
fd6c91e
Update float doc in builtins (move from Doc/library)
Qanty228 Sep 21, 2026
9c889a5
Make examples not too verbose in float doc
Qanty228 Sep 21, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion Doc/builtins/functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ are always available. They are listed here in alphabetical order.
single: NaN
single: Infinity

Return a floating-point number constructed from a number or a string.
Return a floating-point number constructed from a number, a string, or a bytes-like object.

Examples:

Expand All @@ -834,6 +834,10 @@ are always available. They are listed here in alphabetical order.
1000000.0
>>> float('-Infinity')
-inf
>>> float(b'12.67')
12.67
>>> float(bytearray(b'-2.5'))
-2.5

If the argument is a string, it should contain a decimal number, optionally
preceded by a sign, and optionally embedded in whitespace. The optional
Expand All @@ -859,6 +863,9 @@ are always available. They are listed here in alphabetical order.
Case is not significant, so, for example, "inf", "Inf", "INFINITY", and
"iNfINity" are all acceptable spellings for positive infinity.

If the argument is a bytes-like object, it must contain only ASCII characters
that conform to the :token:`~float:floatvalue` rule.

Otherwise, if the argument is an integer or a floating-point number, a
floating-point number with the same value (within Python's floating-point
precision) is returned. If the argument is outside the range of a Python
Expand Down
4 changes: 2 additions & 2 deletions Objects/clinic/floatobject.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Objects/floatobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -1560,12 +1560,12 @@ float.__new__ as float_new
x: object(c_default="NULL") = 0
/

Convert a string or number to a floating-point number, if possible.
Convert a string, number, or bytes-like object to a float, if possible.
Comment thread
skirpichev marked this conversation as resolved.
[clinic start generated code]*/

static PyObject *
float_new_impl(PyTypeObject *type, PyObject *x)
/*[clinic end generated code: output=ccf1e8dc460ba6ba input=55909f888aa0c8a6]*/
/*[clinic end generated code: output=ccf1e8dc460ba6ba input=27eb1f7c62226a39]*/
{
if (type != &PyFloat_Type) {
if (x == NULL) {
Expand Down
Loading