Role:
Basestring is a superclass (parent class) of STR and Unicode, and therefore cannot be invoked and instantiated, but can be used to determine whether an object is an instance of STR or Unicode, isinstance (obj, basestring) Equivalent to Isinstance (obj, (str, Unicode));
Note:
This function is introduced after the python2.3 version, compatible with python2.3 later python2 versions. Note: This function is discarded in python3, so the function cannot be used in Python3.
Instance:
1>>> Isinstance ("Hello World", str)2 True3>>> Isinstance ("Hello World", basestring)4 True5>>> isinstance (U"Hello", Unicode)6 True7>>> isinstance (U"Hello", basestring)8True
A quick and easy way to check whether an object is a string or Unicode object is to use the built-in isinstance and basestring, as follows:
1 def isastring (anobj): 2 return isinstance (anobj, basestring)
Python basestring ()