Python | Check if a given object is list or not

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

Method #1: Using isinstance

filter_none

edit
close

play_arrow

link
brightness_4
code

# 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")

chevron_right


Output:



your object is a list !
your object is not a list

 
Method #2: Using type(x)

filter_none

edit
close

play_arrow

link
brightness_4
code

# 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")

chevron_right


Output:

your object is a list
your object is not a list


My Personal Notes arrow_drop_up

Programming freaktech Enthusiast and have interest in learning new upcoming technologies

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.