Python | Check If A Given Object Is A List Or Not Last Updated : 16 Apr, 2025 Comments Improve Suggest changes Like Article Like Report 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. Python if isinstance([1, 2, 3], list): print("Object is a list") else: print("Object is not a list") if isinstance("12345", list): print("Object is a list") else: print("Object is not a list") OutputObject 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. Python l1 = [1, 2, 3] l2 = (10, 20, 30) # A tuple if type(l1) is list: print("Object is a list") else: print("Object is not a list") if type(l2) is list: print("Object is a list") else: print("Object is not a list") OutputObject 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__ AttributeTo check if an object is a list , we can use the __class__ attribute and compare it to the list type: Python l1 = [1, 2, 3, 4, 5] l2 = (12, 22, 33) if l1.__class__ == list: print("input is a list") else: print("input is not a list") if l2.__class__ == list: print("input is a list") else: print("input is not a list") Outputinput 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 More infoAdvertise with us Next Article Python | Check If A Given Object Is A List Or Not garg_ak0109 Follow Improve Article Tags : Python Python Programs python-list Python list-programs Practice Tags : pythonpython-list Similar Reads Python | Check if a list exists in given list of lists Given a list of lists, the task is to check if a list exists in given list of lists. Input : lst = [[1, 1, 1, 2], [2, 3, 4], [1, 2, 3], [4, 5, 6]] list_search = [4, 5, 6] Output: True Input : lst = [[5, 6, 7], [12, 54, 9], [1, 2, 3]] list_search = [4, 12, 54] Output: False Letâs discuss certain ways 4 min read Check If Value Exists in Python List of Objects When working with Python, we might need to check whether a specific value exists in a list of objects. This problem often arises when dealing with data stored as objects and we want to verify the presence of a specific property value. Using any() Function with List Comprehensionany() function is an 4 min read Python program to check if a given string is Keyword or not This article will explore how to check if a given string is a reserved keyword in Python. Using the keyword We can easily determine whether a string conflicts with Python's built-in syntax rules.Using iskeyword()The keyword module in Python provides a function iskeyword() to check if a string is a k 2 min read Check if a Nested List is a Subset of Another Nested List - Python The task is to check if all sublists in one nested list are present in another nested list. This is done by verifying whether each sublist in the second list exists in the first list.For example, given list1 = [[2, 3, 1], [4, 5], [6, 8]] and list2 = [[4, 5], [6, 8]], we check if both [4, 5] and [6, 4 min read Python - Check if any list element is present in Tuple Given a tuple, check if any list element is present in it. Input : test_tup = (4, 5, 10, 9, 3), check_list = [6, 7, 10, 11] Output : True Explanation : 10 occurs in both tuple and list. Input : test_tup = (4, 5, 12, 9, 3), check_list = [6, 7, 10, 11] Output : False Explanation : No common elements. 6 min read Python - Check if all elements in List are same To check if all items in list are same, we have multiple methods available in Python. Using SetUsing set() is the best method to check if all items are same in list. Pythona = [3, 3, 3, 3] # Check if all elements are the same result = len(set(a)) == 1 print(result) OutputTrue Explanation:Converting 3 min read Python Check if Nonetype or Empty In Python, it's common to check whether a variable is of NoneType or if a container, such as a list or string, is empty. Proper handling of such scenarios is crucial for writing robust and error-free code. In this article, we will explore various methods to check if a variable is either of NoneType 3 min read Python | Check if element exists in list of lists Given a list of lists, the task is to determine whether the given element exists in any sublist or not. Given below are a few methods to solve the given task. Method #1: Using any() any() method return true whenever a particular element is present in a given iterator. Python3 # Python code to demons 5 min read Python | Check if all elements in a list are identical Given a list, write a Python program to check if all the elements in that list are identical using Python. Examples: Input : ['a', 'b', 'c'] Output : False Input : [1, 1, 1, 1] Output : TrueCheck if all elements in a list are identical or not using a loop Start a Python for loop and check if the f 5 min read Python program to check if any key has all the given list elements Given a dictionary with list values and a list, the task is to write a Python program to check if any key has all the list elements. Examples: Input : test_dict = {'Gfg' : [5, 3, 1, 6, 4], 'is' : [8, 2, 1, 6, 4], 'best' : [1, 2, 7, 3, 9], 'for' : [5, 2, 7, 8, 4, 1], 'all' : [8, 5, 3, 1, 2]}, find_li 7 min read Like