Ask Question

Python - test if variable is a string

DavidX02/07/2013 03:59 PM (Edited 02/07/2013 03:59 PM) | Report
In Python 2.x - string can be str or unicode, so the test is:

isinstance(s, basestring)

In Python 3.x - there are only unicode strings (str):

isinstance(s, str)

Answers

Add a answer ▾

Discussion

 Add a question comment ▾