Hashirama Senju
Hashirama Senju

Reputation: 1

printing a type value in string format

I'm trying to print the the datatype of a value in string format.

When I use the str() function to do this it however still prints it as a type value.

data = str(type(4.5))
print(data , type(data))

OUTPUT: <class 'float'> <class 'str'>

The output I'm expecting OUTPUT: float <class 'str'>

Upvotes: 0

Views: 31

Answers (1)

chepner
chepner

Reputation: 531055

You are looking for the __name__ attribute.

>>> type(4.5).__name__
'float'

Upvotes: 1

Related Questions