Programming/Python

Python instance check

Roiei 2021. 12. 13. 17:30
반응형

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
반응형