mirror of
https://github.com/python/cpython
synced 2024-09-05 00:05:39 +00:00
bpo-20692: Add Programming FAQ entry for 1.__class__ error. (GH-28918)
To avoid error, add either space or parentheses.
This commit is contained in:
parent
678433f25e
commit
380c440875
|
@ -836,6 +836,27 @@ ago? ``-190 % 12 == 2`` is useful; ``-190 % 12 == -10`` is a bug waiting to
|
|||
bite.
|
||||
|
||||
|
||||
How do I get int literal attribute instead of SyntaxError?
|
||||
----------------------------------------------------------
|
||||
|
||||
Trying to lookup an ``int`` literal attribute in the normal manner gives
|
||||
a syntax error because the period is seen as a decimal point::
|
||||
|
||||
>>> 1.__class__
|
||||
File "<stdin>", line 1
|
||||
1.__class__
|
||||
^
|
||||
SyntaxError: invalid decimal literal
|
||||
|
||||
The solution is to separate the literal from the period
|
||||
with either a space or parentheses.
|
||||
|
||||
>>> 1 .__class__
|
||||
<class 'int'>
|
||||
>>> (1).__class__
|
||||
<class 'int'>
|
||||
|
||||
|
||||
How do I convert a string to a number?
|
||||
--------------------------------------
|
||||
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
Add Programming FAQ entry explaining that int literal attribute access
|
||||
requires either a space after or parentheses around the literal.
|
Loading…
Reference in a new issue