亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

isinstance的參數

isinstance的參數是不是只能是str?還是分不同情況

正在回答

1 回答

isinstance函數的原型是:


isinstance(object,?classinfo)


Return true if the?object?argument is an instance of the?classinfo?argument, or of a (direct or indirect) subclass thereof. Also return true if?classinfo?is a type object (new-style class) and?object?is an object of that type or of a (direct or indirect) subclass thereof. If?object?is not a class instance or an object of the given type, the function always returns false. If?classinfo?is neither a class object nor a type object, it may be a tuple of class or type objects, or may recursively contain other such tuples (other sequence types are not accepted). If?classinfo?is not a class, type, or tuple of classes, types, and such tuples, a?TypeError?exception is raised.

Changed in version 2.2: Support for a tuple of type information was added.

其中的classinfo指的是某種類型,比如常用的unicode:?
isinstance(some_str, unicode)?
來判斷是否是unicode類型的字符。但是想要知道其他還有哪些類型,網上沒找到具體說明,后來還是自己在python安裝后,自帶的的英文manual中找到了:

5.4. Numeric Types —?int,?float,?long,?complex

5.6. Sequence Types —?str,?unicode,?list,?tuple,?bytearray,?buffer,?xrange

5.7. Set Types —?set,?frozenset

5.8. Mapping Types —?dict

這樣,才知道,關于想要判斷某個變量的類型,就可以去手冊里面找到對應的變量名,然后測試是否是該類型變量了。

0 回復 有任何疑惑可以回復我~
#1

qq_神的一滴_03589442 提問者

非常感謝:多謝多謝,辛苦辛苦
2016-07-07 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消
初識Python
  • 參與學習       758397    人
  • 解答問題       8967    個

學python入門視頻教程,讓你快速入門并能編寫簡單的Python程序

進入課程

isinstance的參數

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號