gpt4 book ai didi

python - basestring 和 types.StringType 之间的 python 区别?

转载 作者:太空狗 更新时间:2023-10-29 17:25:00 24 4
gpt4 key购买 nike

有什么区别:

isinstance(foo, types.StringType)

isinstance(foo, basestring)

?

最佳答案

对于 Python2:basestringstrunicode 的基类,而 types.StringType < em>是 str。如果要检查某物是否为字符串,请使用 basestring。如果你想检查某物是否是字节串,使用 str 而忘记 types

关于python - basestring 和 types.StringType 之间的 python 区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1633082/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com