Python Practice › If-Else Programs › Program 46
Check if a value is a list
Write a Python program to check whether a value is a list.
Input
[1, 3, 6, 8], (1, 3)
Output
[1, 3, 6, 8] True (1, 3) False
Approach
- Use
isinstance(value, list).
Solution
for value in [[1, 3, 6, 8], (1, 3)]: print(value, isinstance(value, list))Output
[1, 3, 6, 8] True (1, 3) False
Line by line
Line 2
A tuple is a different type, so it returns False.
Learn the concept
New to this topic? Read the lesson, then come back.