About IsInstance Use (excerpt)

xiaoxiao2021-03-06  15

When the type () function provides an object's type, you can also use the isInstance () function to test objects to determine if it is an instance of a particular type or custom class:

>>> print isinstance .__ doc__

IsInstance (Object, Class-or-Type-or-tuple) -> Boolean

RETURN WHETHER An Object IS An Instance of a Class OR of a Subclass Thereof.

With a type as second argument, return WHether That Is The Object's Type.

The Form Using A Tuple, IsInstance (X, (A, B, ...)), IS A Shortcut for

IsInstance (X, A) or isinstance (X, b) or ... (etc.).

>>> IsInstance (42, STR)

0

>>> IsInstance ('a string', int)

0

>>> IsInstance (42, int)

1

>>> IsInstance ('a string', str)

1

转载请注明原文地址:https://www.9cbs.com/read-46278.html

New Post(0)