国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

pythonisinstance判斷各種類型的小細(xì)節(jié)

2019-11-14 17:41:21
字體:
供稿:網(wǎng)友

1. 基本語法

isinstance(objectclassinfo)

Return true if the object argument is an instance of the classinfo argument, or of a (direct, indirect or virtual) 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, indirect or virtual) 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.

 

classinfo 處可以是 a class, type, or tuple of classes and types,

如果是 tuple,則滿足 tuple 中的任何一個(gè)即返回 True

2. 字符串的類型判斷。

字符串,分為 str 和 unicode,二者均繼承自 basestring

>>> isinstance(u'3.0', unicode)True>>> isinstance('3.0', str)True>>> isinstance(u'3.0', str)False>>> isinstance(u'3.0', str)False>>> isinstance(u'3.0', basestring)True>>> isinstance('3.0', basestring)True

3. 數(shù)字的類型判斷

數(shù)字分為 int 和 float,暫未發(fā)現(xiàn)二者共同的有效父類。

可以用 (int, float) tuple 來判斷是否為數(shù)字(int 或 float)

>>> isinstance('3', (int, float))False>>> isinstance(3.0, (int, float))True>>> isinstance(3, (int, float))True>>> isinstance(3.0, float)True>>> isinstance(3.0, int)False>>> isinstance(3, float)False>>> isinstance(3, int)True

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 河津市| 方正县| 万全县| 邯郸市| 华阴市| 游戏| 松滋市| 凌云县| 万年县| 米易县| 丰都县| 潢川县| 太原市| 皮山县| 卢龙县| 黄大仙区| 永年县| 永登县| 偃师市| 元氏县| 浦县| 尉犁县| 张家口市| 高平市| 秦皇岛市| 青河县| 杨浦区| 肇东市| 信丰县| 平阳县| 河曲县| 思南县| 龙泉市| 观塘区| 武汉市| 武汉市| 盐城市| 阿巴嘎旗| 芦山县| 五指山市| 尼玛县|