Python/list인지 dict인지 판단

Case 1. type(x)
a = [10, 20, 30, 40]
>>> type(a)
<class 'list'>
>>> type(a) is list
True
>>> type(a) is dict
False
>>> type(a).__name__
list

Case 2. isinstance
a = [10, 20, 30, 40]
>>> isinstance(a, list)
True
>>> isinstance(a, dict)
False
b = {}
b["one"] = 10
b["two"] = 20
b["three"] = 30
b["four"] = 40
>>> isinstance(b, dict)
True
>>> isinstance(b, list)
False


이 글에는 0 개의 댓글이 있습니다.