Python isinstance() function

Instance

Check if the number 10 is an integer:

x = isinstance(10, int)

Run instance

Definition and usage

If the specified object has the specified type, the isinstance() function returns True, otherwise returns False.

If the type parameter is a tuple, then if the object is one of the types in the tuple, this function will return True.

Syntax

isinstance(object, type)

Parameter value

Parameter Description
object Mandatory. Object.
type Type or class, or tuple of type and/or class.

More instances

Instance

Check ke "Hello" ne kan type parameter tsofinsa

x = isinstance("Hello", (float, int, str, list, dict, tuple))

Run instance

Instance

Check ke y ne instance of myObj:

class myObj:
  name = "Bill"
y = myObj()
x = isinstance(y, myObj)

Run instance

Pages related

Reference Manual:issubclass() FanninKai sake object ne da aka na object na farko