python isinstance_Python内置isinstance函数详细介绍
英文文档:
isinstance(object, classinfo)
Return true if the object argument is an instance of the classinfo argument, or of a (direct, indirect or virtual) subclass thereof. If object is not an object of the given type, the function always returns false. If classinfo is a tuple of type objects (or recursively, other such tuples), return true if object is an instance of any of the types. If classinfo is not a type or tuple of types and such tuples, a TypeError exception is raised.
说明:
1. 函数功能用于判断对象是否是类型对象的实例,object参数表示需要检查的对象,calssinfo参数表示类型对象。
2. 如果object参数是classinfo类型对象(或者classinfo类对象的直接、间接、虚拟子类)的实例,返回True。>>> isinstance(1,int)
True
>>> isinstance(1,str)
False
# 定义3各类:C继承B,B继承A
>>> class A:
pass
>>> class B(A):
pass
>>> class C(B):
pass
>>> a = A()
>>> b = B()
>>> c = C()
>>> isinstance(a,A) #直接实例
True
>>> isinstance(a,B)
False
>>> isinstance(b,A) #子类实例
True
>>> isinstance(c,A) #孙子类实例
True
3. 如果object参数传入的是类型对象,则始终返回False。>>> isinstance(str,str)
False
>>> isinstance(bool,int)
False
4. 如果classinfo类型对象,是多个类型对象组成的元组,如果object对象是元组的任一类型对象中实例,则返回True,否则返回False。>>> isinstance(a,(B,C))
False
>>> isinstance(a,(A,B,C))
True
5. 如果classinfo类型对象,不是一个类型对象或者由多个类型对象组成的元组,则会报错(TypeError)。>>> isinstance(a,[A,B,C])
Traceback (most recent call last):
File "", line 1, in
isinstance(a,[A,B,C])
TypeError: isinstance() arg 2 must be a type or tuple of types
python isinstance_Python内置isinstance函数详细介绍相关推荐
- python中isinstance用法_Python内置isinstance函数详细介绍
英文文档: isinstance(object, classinfo) Return true if the object argument is an instance of the classin ...
- python中bytearray函数_Python内置bytearray函数详细介绍
英文文档: classbytearray([source[, encoding[, errors]]]) Return a new array of bytes. The bytearray clas ...
- python中bool函数的作用_Python内置bool函数详细介绍
英文文档: classbool([x]) Return a Boolean value, i.e. one of True or False. x is converted using the sta ...
- python模拟内置函数all_Python内置all函数详细介绍
英文文档: all(iterable) Return True if all elements of the iterable are true (or if the iterable is empt ...
- int是python的内置函数吗_Python内置int函数详细介绍
英文文档: class int(x=0) class int(x, base=10) Return an integer object constructed from a number or str ...
- python布尔函数_Python内置bool函数详细介绍
英文文档: classbool([x]) Return a Boolean value, i.e. one of True or False. x is converted using the sta ...
- BeanShell 内置变量 prev详细介绍
前提 BeanShell 有的内置变量,JSR223 也会有对应的变量,这里 JSR223 效率更高,所以以它为栗子 简单介绍 prev 提供对当前取样器结果的访问能力 prev 映射 org.apa ...
- vue 路由的内置组件 router-view 详细介绍(有图有真相)
介绍 当你的地址符合我的路由要求的时候,会把路由的组件在 你的界面中呈现,而这个界面实在 App.vue里面 当你打开 App.vue就会在里面发现这两个组件 这两个是 vue 给你提供的两个 vue ...
- python中内置数学函数详解和实例应用之三角函数_初级阶段(二)
学习目标: 利用python进行三角函数运算 学习内容: python中的三角函数合集和应用实例 转载请注明出处! 学习产出: 环境:python 3.7, 利用shell进行实例操作. Note: ...
最新文章
- 一些琐碎+分不清的知识点
- require.context实现前端工程自动化
- LeetCode 5268. 找出两数组的不同(set)
- Linux学习总结(13)——在阿里云的ubuntu上部署个人服务
- IOS Socket 01-网络协议基础知识
- 打印机共享与文件夹win10共享教程
- 【翻译工具】如何复活谷歌翻译(网页翻译)
- Opencv打开basler相机——实现显示视频、保存图片、记录视频(Windows下)
- 身份证真伪辨别python版
- 服务器如果清理垃圾文件,为citrix服务器清理垃圾文件事件
- 灵感来了挡也挡不住,基于Redis解决业务场景中延迟队列
- Java小案例--自助饮品消费系统
- 基金申请:关键科学问题,不是科学问题
- PIC 1508 DAC使用
- 对 Spring 的核心(AOP 和 IOC)的理解(大白话)
- 联想拯救者R7000P开箱检查测试
- 索尼z5android 7.1,真良心!索尼Xperia Z3+系列升至Android 7.0
- CSRF的攻击与防御原理
- c# 网络字节序数据传输
- Oracle中表列由VARCHAR2类型改成CLOB
热门文章
- 从零开始学架构——架构设计流程
- Redis 事务使用详解
- ETL常用的三种工具介绍及对比 Datastage,Informatica 和 Kettle
- linux创建pc目录,linux中mkdir创建目录命令使用说明
- 伤感语录:浅唱,没人懂的悲伤
- 【拓展】937- 科普:探讨浏览器指纹
- cs231n Assignment 1# two layer net详细答案及总结
- CAN片选使用(英飞凌)
- HTML中如何两行字如何顶格写,文件每行字都不顶格,如何做到顶格
- 北京理工大学2023年软件工程需求与uml建模——第14组旅游景区智能分析平台项目进度(V3.0最终版)