How python verifies object types
Editor to share with you how to test the object type of python, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to understand it!
Verify the object type
Verifying object types is part of Python's introspection capabilities. Sometimes, before applying the corresponding function, you need to know whether the object is of a certain type. Therefore, you can use the type () function or the isinstance () function, which is more flexible and can perform one-to-many tests.
Def check_type (number):... If type (number) = = int:... Print ('do something with anint')... If isinstance (number, (int,float)): Print ('do something with anint or float'). > check_type (5) do something with anint do something with anint or float > check_type (4. 2) do something with anint or float is all the content of this article "how to check object types in python". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!