当前位置:网站首页>Isinstance() function usage
Isinstance() function usage
2022-06-26 08:51:00 【Feng Dashao】
isinstance() Function to determine whether an object is a known type , It is usually used to judge whether two types are the same .

example :
1. When you type x < y when ,num Of Ternary expression return x Value by 100, Its type passes int After the transformation , and isinstance Of classinfo params “int” Contrast type , So it is concluded that by “ True"

2. contrary , When you type x < y when ,num Of Ternary expression return " x < y " , The type of “str”, and isinstance Of classinfo params “int” Contrast type , So it is concluded that by “ False"

3. When you type x < y when ,num Of Ternary expression return “False” , and isinstance Of classinfo params “int” Contrast type , because False It can also be understood as equivalent to 0, and int Type match , So it is concluded that by “ True" .

4. When you type x < y when ,num Of Ternary expression return “False” , and isinstance Of classinfo params “str” Contrast type , because False It belongs to bool Boolean type , Many times, it will be accidentally misunderstood as str. So it is concluded that by “ False " .

5. When you type x < y when ,num Of Ternary expression return “False” , and isinstance Of classinfo params “bool” Contrast type , So it is concluded that by “ True" .

Be careful : params in , If classinfo Type is string , It has to be for str, If written string, Will report a mistake .

type() And isinstance() difference :
establish Thursday class and Inherit Thursday Of Friday
print(isinstance(Thursday(),Thursday)) # The output is True
print(type(Thursday()) == Thursday) # The output is True
print(isinstance(Friday(),Thursday)) # The output is True, Friday() Inherited from Thursday
print(type(Friday()) == Thursday) # The output is False, type() Function does not recognize subclasses , Inheritance relationship of parent class

边栏推荐
- WBC learning notes (II): practical application of WBC control
- STM32 project design: an e-reader making tutorial based on stm32f4
- 在同花顺开户证券安全吗,
- Comparison between Apple Wireless charging scheme and 5W wireless charging scheme
- Relation extraction model -- spit model
- Embedded Software Engineer (6-15k) written examination interview experience sharing (fresh graduates)
- How to realize wireless Ethernet high-speed communication for multiple Mitsubishi PLCs?
- [已解决]setOnNavigationItemSelectedListener()被弃用
- Koa_ mySQL_ Integration of TS
- Installation of jupyter
猜你喜欢

How to realize wireless Ethernet high-speed communication for multiple Mitsubishi PLCs?

STM32 project design: smart home system design based on stm32

关于极客时间 | MySQL实战45讲的部分总结

Selenium 搭建 Cookies池 绕过验证反爬登录

Esp8266wifi module tutorial: punctual atom atk-esp8266 for network communication, single chip microcomputer and computer, single chip microcomputer and mobile phone to send data

Discrete device ~ resistance capacitance

Learning signal integrity from scratch (SIPI) -- 3 challenges faced by Si and Si based design methods

And are two numbers of S

Partial summary of 45 lectures on geek time MySQL

Exploration of webots and ROS joint simulation (I): software installation
随机推荐
Convex optimization of quadruped
9. code generation
SOC wireless charging scheme
leetcode2022年度刷题分类型总结(十二)并查集
STM32 based d18s20 (one wire)
Summary of common instructions for arm assembly
Embedded Software Engineer (6-15k) written examination interview experience sharing (fresh graduates)
STM32 porting mpu6050/9250 DMP official library (motion_driver_6.12) modifying and porting DMP simple tutorial
Exploration of webots and ROS joint simulation (II): model import
WBC learning notes (II): practical application of WBC control
(5) Matrix key
ROS learning notes (5) -- Exploration of customized messages
Recovering the system with Clonezilla USB disk
Zlib static library compilation
Batch execute SQL file
1.17 daily improvement of winter vacation learning (frequency school and Bayesian school) and maximum likelihood estimation
Detailed explanation of SOC multi-core startup process
Implementation of ffmpeg audio and video player
ZLMediaKit推流拉流测试
Pandas vs. SQL 1_ nanyangjx