In Python 2.x, you would do
(在Python 2.x中,你会这样做)
isinstance(s, basestring)
basestring
is the abstract superclass of str
and unicode
.
(basestring
是str
和unicode
的抽象超类 。)
It can be used to test whether an object is an instance of str
or unicode
. (它可用于测试对象是str
还是unicode
的实例。)
In Python 3.x, the correct test is
(在Python 3.x中,正确的测试是)
isinstance(s, str)
The bytes
class isn't considered a string type in Python 3.
(在Python 3中, bytes
类不被视为字符串类型。)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…