Basestring ()
Description: Basestring is a superclass of STR and Unicode (parent class), which is also an abstract class, and therefore cannot be called and instantiated, but can be used to determine whether an object is a str or an instance of Unicode, isinstance (obj, basestring) Equivalent to Isinstance (obj, (str, Unicode));
Version: python2.3 version later introduced this function, compatible with python2.3 later python2 versions. Note: This function is discarded in python3, so the function cannot be used in Python3.
Example:
>>> isinstance ("Hello World", str)
True
>>> isinstance ("Hello World", basestring)
True
>>> isinstance (U "Hello", Unicode)
True
>>> isinstance (U "Hello", basestring)
True
Here's a practical one.
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:
def isastring (anobj):
Return Isinstance (Anobj, basestring)
This function is still useful, but be aware of its version requirements