본문 바로가기
Programing Language/Python

[Python] 타입 비교

by pcm9881 2023. 2. 21.

문자 비교

if isinstance('문자', str): # True

or

if type('문자') is str: # True

 

 

숫자 비교

if isinstance(9, int): # True

or

if type(9) is int: # True

 

 

참조

[stackoverflow]: https://stackoverflow.com/questions/707674/how-to-compare-type-of-an-object-in-python

 

How to compare type of an object in Python?

Basically I want to do this: obj = 'str' type ( obj ) == string I tried: type ( obj ) == type ( string ) and it didn't work. Also, what about the other types? For example, I couldn't replicate

stackoverflow.com

 

728x90

댓글