lintcode-solutions
  • LintCode 刷题笔记
  • 课程笔记
    • Backtracking
    • Binary Search
    • Divide & Conquer
    • Breadth First Search
    • Depth First Search
    • Linked List & Array
    • Two Pointers
    • Stack, Queue and Heap
    • Dynamic Programming
    • Two Pointers Advanced
    • Union Find and Trie
    • Dynamic Programming Advanced
  • 基础知识储备
    • Python
      • Stack and Queue
      • Namedtuple
      • Priority Queue
      • isinstance()
      • OrderedDict
      • set and frozen set
      • Counter
      • Heap
    • Bit Manipulation
    • Fenwick Tree or Binary Indexed Tree
    • Rabin-Karp Algorithm
    • Sort
      • Merge Sort
      • Quick Sort
      • Heap Sort
  • LintCode 练习题
    • Binary Search
  • OJ Review
    • Aug 7, 2018
    • Aug 8, 2018
    • Aug 9, 2018
    • Aug 13, 2018
    • Aug 17, 2018
    • Aug 19, 2018
    • Aug 24, 2018
    • Aug 26, 2018
    • Aug 27, 2018
    • Aug 29, 2018
    • Sep 1, 2018
    • Sep 2, 2018
    • Sep 3, 2018
    • Sep 4, 2018
    • Oct 28, 2018
    • Nov 13, 2018
Powered by GitBook
On this page
  • isinstance()
  • isinstance() Parameters
  • Return Value from isinstance()
  • References
  1. 基础知识储备
  2. Python

isinstance()

isinstance()

isinstance(object, classinfo)

isinstance() Parameters

The isinstance() takes two parameters:

  • object - object to be checked

  • classinfo - class, type, or tuple of classes and types

Return Value from isinstance()

The isinstance() returns:

  • True if the object is an instance or subclass of a class, or any element of the tuple

  • False otherwise

If classinfo is not a type or tuple of types, a TypeError exception is raised.

class Foo:
  a = 5
  
fooInstance = Foo()

print(isinstance(fooInstance, Foo))
print(isinstance(fooInstance, (list, tuple)))
print(isinstance(fooInstance, (list, tuple, Foo)))

Output:

True
False
True

References

https://www.programiz.com/python-programming/methods/built-in/isinstance

PreviousPriority QueueNextOrderedDict

Last updated 6 years ago