아미(아름다운미소)

Python type() Check Python data type 본문

랭귀지/PYTHON

Python type() Check Python data type

유키공 2018. 10. 1. 09:30

Check Python data type

Python에서는 데이터타입을 확인 하기 위해서는 type() 을 사용하여 확인 합니다.

print(type(123))
print(type(12.3))
print(type('123'))
# <class 'int'>
# <class 'float'>
# <class 'str'>
 
print(type([]))
print(type([1, 2, 3, 4, 5]))
print(type({}))
print(type(()))
# <class 'list'>
# <class 'list'>
# <class 'dict'>
# <class 'tuple'>
 
print(type(None))
# <class 'NoneType'>
print(type('한글'))
print(type(u'한글'))
# <class 'str'>
# <class 'str'>
Python 3에서는 문자열이 항상 유니코드로 처리되므로 u 표기 필요없습니다.



Comments