Python instance check

2021. 12. 13. 17:30Programming/Python

    목차
반응형

Like any other programminmg languages, Python also provides a way to check what the type of the instance is.
Simple, by using 'isinstance' or 'type' function, it is possible to check instance's type.

the following code is about using 'isinstance and type'

val = 7
ovals = [1, 2]
vals = []
if isinstance(val, int):
    vals += val,

if type(ovals) == list:
    vals += ovals
반응형

'Programming > Python' 카테고리의 다른 글

파이썬 윤년 (Python leap year)  (0) 2021.12.24
Python: 원소의 중복 제거  (0) 2021.12.15
[Python] Lambda expression (람다 표현식)  (0) 2021.12.13
Python access member as string  (0) 2021.12.10
Python access member with string  (0) 2021.12.10