diff -r fd53f083768c Doc/faq/programming.rst --- a/Doc/faq/programming.rst Sat Mar 08 21:40:29 2014 -0500 +++ b/Doc/faq/programming.rst Wed Mar 12 22:37:51 2014 +0100 @@ -1601,6 +1601,33 @@ 13891296 +.. _faq-int-type: + +Syntax error while looking up an attribute on an integer literal +---------------------------------------------------------------- + +You get a syntax error when trying to look for an attribute on +``int`` value as follows. + + >>> 5.__class__ + File "", line 1 + 5.__class__ + ^ + SyntaxError: invalid syntax + +This is because the Python parser considers that a period written after +a number literal is a decimal point, so to turn that period into an attribute +access you have to add either a parentheses or a space around the literal. +In the above case, the tokenizer sees the '.' as making the token a float, +and ``5.__class__`` is not a valid float token. + +To look up an attribute on an integer literal, separate the literal from +the period with either a space or parentheses. + + >>> (5).__class__ + + + Modules ======= diff -r fd53f083768c Doc/tutorial/classes.rst --- a/Doc/tutorial/classes.rst Sat Mar 08 21:40:29 2014 -0500 +++ b/Doc/tutorial/classes.rst Wed Mar 12 22:37:51 2014 +0100 @@ -470,6 +470,7 @@ Each value is an object, and therefore has a *class* (also called its *type*). It is stored as ``object.__class__``. +See also :ref: `faq-int-type` .. _tut-inheritance: