Check if a value is a list

EasyIf-Else Programs · 46 of 64

Write a Python program to check whether a value is a list.

Advertisement
Input
[1, 3, 6, 8], (1, 3)
Output
[1, 3, 6, 8] True
(1, 3) False

Approach

  1. Use isinstance(value, list).

Solution

Python
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.

Advertisement

Learn the concept

New to this topic? Read the lesson, then come back.

More if-else programs

← All 64 If-Else Programs