ホームページ  >  に質問  >  本文

python3中怎么判断传入的参数是否是unicode

网上的教程都说使用isinstance( XXX , unicode)来判断
但是我在python3下这么使用会报name 'unicode' is not defined的错误,想看一下isinstance()是怎么实现的,传入参数的说明,结果发现isinstance的定义是下面这个样子,完全看不出想要判断unicode该传入什么参数,顺带问一下为什么python好多自带的参数都是这么定义的,def XXX(): return none,没有功能实现的代码

def isinstance(object, class_or_type_or_tuple):
  """ isinstance(object, class-or-type-or-tuple) -> bool
  
  Return whether an object is an instance of a class or of a subclass thereof.
  With a type as second argument, return whether that is the object's type.
  The form using a tuple, isinstance(x, (A, B, ...)), is a shortcut for
  isinstance(x, A) or isinstance(x, B) or ... (etc.). """
  return None

回到正题,python3下该怎么判断是否unicode呢?

黄舟黄舟2713日前549

全員に返信(2)返信します

  • PHP中文网

    PHP中文网2017-04-18 09:54:30

    Python 3 の基本的な str は Unicode であるため、str を直接判断できます。

    リーリー

    返事
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-18 09:54:30

    cpython の最下層は C で実装されています。組み込み関数とオブジェクトの py ソース コードは単なる装飾であり、コメントを提供するためのものです

    返事
    0
  • キャンセル返事