Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
21 changes: 21 additions & 0 deletions Doc/faq/programming.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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?
--------------------------------------

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Add Programming FAQ entry explaining that int literal attribute access
requires either a space after or parentheses around the literal.