user1313198
user1313198

Reputation:

Python type as a string

I'm attempting to display a string that provides the type of a given variable.

When I try the following:

'This is a '+str(type(somevariable))

the output is "This is a <type 'float'>", instead of "This is a float".

How do I get the output I want?

Upvotes: 1

Views: 177

Answers (2)

Sven Marnach
Sven Marnach

Reputation: 602635

'This is a ' + type(somevariable).__name__

Upvotes: 7

jmhl
jmhl

Reputation: 1696

somevariable.__class__.__name__

is one way.

Upvotes: 4

Related Questions