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
{{ message }}
Repository navigation
Programming FAQ about "How do I convert a string to a number?" contains a typo #84520
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=<Date2020-04-25.06:33:42.992>created_at=<Date2020-04-20.19:37:45.484>labels= ['type-feature', '3.8', '3.9', 'docs']
title='Programming FAQ about "How do I convert a string to a number?" contains a typo'updated_at=<Date2020-04-25.06:33:42.991>user='https://github.com/Dominik1123'
I'm no linguist, but I feel both expressions in the subordinate clause have their purposes, with respect to the the main clause:
int('0144') == 144 to show what works
int('0x144') to show what does not work
I don't believe the octal notation was meant in the first example, as the equality wouldn't then hold, even if somehow the typecast worked (which it doesn't). The point was to positively reinforce the idea that the content of the string would be interpreted as a decimal. So something like int('000000144') == 144 would still hold True. Negative reinforcement is provided in the second example.
But I agree that the sentence itself does not clearly separate the two examples, so I would suggest adding a comma after the first example, like so:
By default, these interpret the number as decimal, so that int('0144') == 144, and int('0x144') raises ValueError.
Dominik1123 commented on Apr 20, 2020
Dominik1123mannequin
MannequinAuthor
More actions
Indeed, thanks for clarifying. It seems I misunderstood the example, and perhaps that calls for a better separation. What about adding
By default, these interpret the number as decimal, so that int('0144') == 144 holds true and int('0x144') raises ValueError.
Activity
Dominik1123 commentedon Apr 20, 2020
The paragraph about How do I convert a string to a number? contains the following sentence:
The first part however doesn't raise an error. Most likely octal notation was meant, i.e.
int('0o144') == 144.For consistency with the
int('0x144')part one could also omit the equality comparison, i.e. just writeint('0o144').In order to emphasize that the "and" is not part of the code (though this should be displayed by the browser) once could also write:
(emphasis added)
caje731 commentedon Apr 20, 2020
I'm no linguist, but I feel both expressions in the subordinate clause have their purposes, with respect to the the main clause:
int('0144') == 144to show what worksint('0x144')to show what does not workI don't believe the octal notation was meant in the first example, as the equality wouldn't then hold, even if somehow the typecast worked (which it doesn't). The point was to positively reinforce the idea that the content of the string would be interpreted as a decimal. So something like
int('000000144') == 144would still hold True. Negative reinforcement is provided in the second example.But I agree that the sentence itself does not clearly separate the two examples, so I would suggest adding a comma after the first example, like so:
Dominik1123 commentedon Apr 20, 2020
Indeed, thanks for clarifying. It seems I misunderstood the example, and perhaps that calls for a better separation. What about adding
caje731 commentedon Apr 23, 2020
Yes, I think that's acceptable.
aeros commentedon Apr 24, 2020
New changeset 5aafa54 by Cajetan Rodrigues in branch 'master':
bpo-40340: Separate examples more clearly in the programming FAQ (GH-19688)
5aafa54