Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Python | Check if a given object is list or not

  • Last Updated : 19 Mar, 2019

Given an object, the task is to check whether the object is list or not.

Method #1: Using isinstance




# Python code to demonstrate
# check whether the object 
# is a list or not
  
# initialisation list
ini_list1 = [1, 2, 3, 4, 5]
ini_list2 = '12345'
  
# code to check whether
# object is a list or not
if isinstance(ini_list1, list):
  print("your object is a list !")
else:
    print("your object is not a list")
    
if isinstance(ini_list2, list):
    print("your object is a list")
else:
    print("your object is not a list")
Output:
your object is a list !
your object is not a list

 
Method #2: Using type(x)




# Python code to demonstrate
# check whether object 
# is a list or not
  
# initialisation list
ini_list1 = [1, 2, 3, 4, 5]
ini_list2 = (12, 22, 33)
  
# code to check whether
# object is a list or not
if type(ini_list1) is list:
    print("your object is a list")
else:
    print("your object is not a list")
  
if type(ini_list2) is list:
    print("your object is a list")
else:
    print("your object is not a list")
Output:
your object is a list
your object is not a list

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!