Write a Python program to test if a variable is a list, tuple, or set.

Write a Python program to test if a variable is a list, tuple, or set.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
#x = ['a', 'b', 'c', 'd']
#x = {'a', 'b', 'c', 'd'}
x = ('tuple', False, 3.2, 1)
if type(x) is list:
    print('x is a list')
elif type(x) is set:
    print('x is a set')
elif type(x) is tuple:
    print('x is a tuple')    
else:
    print('Neither a list or a set or a tuple.')

Final output

Leave a Comment