Joan Venge Joan Venge - 2 years ago 73
Python Question

How to compare type of an object in Python?

Basically I want to do this:

obj = 'str'
type ( obj ) == string

I tried:

type ( obj ) == type ( string )

and it didn't work.

Also, what about the other types? For example, I couldn't replicate

Answer Source

In your case, isinstance("this is a string", str) will return True.

You may also want to read this:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download