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


Question

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

1
365
10/1/2016 9:01:50 PM

Python 2

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

Docs.

293
12/22/2017 10:06:33 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon