VOOZH about

URL: https://www.geeksforgeeks.org/python/python-check-if-a-given-object-is-list-or-not/

⇱ Python | Check If A Given Object Is A List Or Not - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Python | Check If A Given Object Is A List Or Not

Last Updated : 11 Jul, 2025

Given an object, the task is to check whether the object is a list or not. Python provides few simple methods to do this and in this article, we'll walk through the different ways to check if an object is a list:

Using isinstance()

isinstance() function checks if an object is an instance of a specific class or data type.


Output
Object is a list
Object is not a list

Explanation:isinstance(obj, list) returns True if obj is a and False if it's not.

Using type()

Another method to check if an object is a list is by using the type() function. This function returns the exact type of an object.


Output
Object is a list
Object is not a list

Explanation:

  • type(obj) returns the exact type (e.g., list, tuple, dict).
  • Unlike isinstance(), it does not consider inheritance, useful when strict type matching is needed.

Using __class__ Attribute

To check if an object is a list , we can use the __class__ attribute and compare it to the list type:


Output
input is a list
input is not a list

Explanation:

  • __class__ returns the class of an object.
  • While it works, it’s less readable and not as commonly used as isinstance().
Comment