How to find out if a Python object is a string?

Matt S. picture Matt S. · Aug 20, 2009 · Viewed 334.4k times · Source

How can I check if a Python object is a string (either regular or Unicode)?

Answer

John Fouhy picture John Fouhy · Aug 20, 2009

Python 2

Use isinstance(obj, basestring) for an object-to-test obj.

Docs.