Difference in python between basestring and types.StringType?

后端 未结 4 1362
一向
一向 2021-02-07 19:25

What\'s the difference between:

isinstance(foo, types.StringType)

and

isinstance(foo, basestring)

?

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-07 19:55

    For Python2: basestring is the base class for both str and unicode, while types.StringType is str. If you want to check if something is a string, use basestring. If you want to check if something is a bytestring, use str and forget about types.

提交回复
热议问题