Python Forum

Full Version: a __class__ syntax error
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm learning the __class__ property,but when I try to execute code below,a syntax error raises:
print(1.__class__)
from my opinion,in python,everything is object,so do number 1,this code should give me "class int" back.am i right?

this is another scenario:
print((1,2)[0].__class__)
this code is OK.I think (1,2)[0] is actually number 1,why this code is OK?
The error in 1.__class__ is generated by the parser because 1. is a possible syntax for the literal real number 1.0, so the parser sees a real number followed by a name, which is an invalid syntax. If you add a space character, it works because 1 . cannot be interpreted as a real number.
>>> 1 .__class__
<class 'int'>