You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The documentation for float doesn't explicitly allow int-like strings, although it does give one as an example. E.g. although float('10') works and returns a float, the documentation implies that it shouldn't.
Maybe remove the indirection (the reference to floating-point literals) from the current documentation and give a direct description of what's permitted instead? That way the information is all in one place. The current documentation feels as though it was a shortcut taken for ease of documentation writing rather than ease of documentation reading.
On the other hand, it's definitely useful for users to know that any string that's acceptable as a floating-point literal is also acceptable as a string argument to float.
There are inaccuracies in the int documentation too, for instance, the handling of leading zeros isn't really described. Also the following isn't correct:
Base 0 means to interpret exactly as a code literal
>>> s = "२३४५६७८९"
>>> int(s, 0)
23456789
>>> eval(s)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", line 1
२३४५६७८९
^
SyntaxError: invalid character '२' (U+0968)
Activity
mdickinson commentedon Dec 22, 2022
Maybe remove the indirection (the reference to floating-point literals) from the current documentation and give a direct description of what's permitted instead? That way the information is all in one place. The current documentation feels as though it was a shortcut taken for ease of documentation writing rather than ease of documentation reading.
On the other hand, it's definitely useful for users to know that any string that's acceptable as a floating-point literal is also acceptable as a string argument to
float
.mdickinson commentedon Dec 22, 2022
Another way in which the indirection is inaccurate is that
float
accepts arbitrary Unicode digits, while literals may only use ASCII digits:hauntsaninja commentedon Dec 22, 2022
There are inaccuracies in the
int
documentation too, for instance, the handling of leading zeros isn't really described. Also the following isn't correct:pythongh-100428: Make int documentation more accurate
pythongh-100428: Make float documentation more accurate
gh-100428: Make float documentation more accurate (#100437)
pythongh-100428: Make float documentation more accurate (pythonGH-100437
pythongh-100428: Make float documentation more accurate (pythonGH-100437
gh-100428: Make float documentation more accurate (GH-100437)
gh-100428: Make float documentation more accurate (GH-100437)
Merged main into regmachine branch (#50)
gh-100428: Make int documentation more accurate (#100436)
pythongh-100428: Make int documentation more accurate (pythonGH-100436)
pythongh-100428: Make int documentation more accurate (pythonGH-100436)
gh-100428: Make int documentation more accurate (GH-100436)
gh-100428: Make int documentation more accurate (GH-100436)