0

I’m learning Python 3.

My code

numbers = [1, 2]
print( type( numbers[0] ))

outputs

<class ‘int’>

How do I print only

‘int’

or

int
Global nomad
  • 1,037
  • 12
  • 25

1 Answers1

3

You can use the __name__ attribute from the type.

>>> type(5).__name__
'int'

Or without using the type built-in:

>>> (5).__class__.__name__
'int'
kalehmann
  • 4,821
  • 6
  • 26
  • 36