1

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?

4
  • 4
    This should work. What error message do you get? Commented Apr 4, 2012 at 15:21
  • 1
    "it's not working" doesn't tell us the problem. Unexpected output? Error message? Elaborate. Commented Apr 4, 2012 at 15:23
  • 1
    Well, I guess it kind of works. The output is "This is a <type 'float'>". I want it to be just "This is a float". Commented Apr 4, 2012 at 15:24
  • 2
    @HarperLee: Please update your question with this information. Commented Apr 4, 2012 at 15:25

2 Answers 2

7
'This is a ' + type(somevariable).__name__
Sign up to request clarification or add additional context in comments.

Comments

4
somevariable.__class__.__name__

is one way.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.