mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +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
2 changed files with 23 additions and 0 deletions
|
@ -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?
|
||||
--------------------------------------
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue