0

When checking the type of int objects in python3 interpreter below error is encounterd:

>>> 3.14.__class__
<class 'float'>

>>> 3.__class__
  File "<stdin>", line 1
    3.__class__
          ^
SyntaxError: invalid syntax

Whereas below code works:

>>> x = 3
>>> x.__class__
<class 'int'>
Ram Meena
  • 361
  • 1
  • 3
  • 9

1 Answers1

1

Do this instead:

>>> type(3.14)
<class 'float'>
>>> type(3)
<class 'int'>
>>> isinstance(3.14, float)
True
>>> isinstance(3, float)
False
>>> isinstance(3.14, int)
False
>>> isinstance(3, int)
True
Ewan Mellor
  • 6,747
  • 1
  • 24
  • 39