isinstance 입력받은 인스턴스의 클래스(class)를 판단하여 참이면 True, 거짓이면 False를 리턴
a = ['a','b',1,3,'c',{"a":1},(9,10,11), [1,2,3,4],100.0]
list_type = [ x for x in a if isinstance(x, list) ]
tuple_type = [ x for x in a if isinstance(x, tuple) ]
dict_type = [ x for x in a if isinstance(x, dict) ]
str_type = [ x for x in a if isinstance(x, str) ]
float_type = [ x for x in a if isinstance(x, float) ]
print(list_type)
print(tuple_type)
print(dict_type)
print(str_type)
print(float_type)
----------------------------------------------------------------
[[1, 2, 3, 4]]
[(9, 10, 11)]
[{'a': 1}]
['a', 'b', 'c']
[100.0]
'Python > Python Programming' 카테고리의 다른 글
[Python] 리스트의 값을 여러 변수에 다중할당 (0) | 2019.10.02 |
---|---|
[Python] itertools을 이용한 곱집합 만들기 (0) | 2019.09.27 |
[Python] 디렉토리 / 파일 유효성 확인 (0) | 2019.09.25 |
[Python] 정규식을 이용하여 문자열에서 숫자와 문자를 제외한 나머지 일괄 변경 시키기 (0) | 2019.09.23 |
[Python] max, min, sum 내장함수 (0) | 2019.08.24 |
[Python] Send Slack Massages and upload file (0) | 2019.08.02 |
jupyter notebook install (windows) 설치 (0) | 2019.07.27 |
[Python] 로그스탬프 UTC 한국시간 계산하기 (0) | 2019.07.02 |