파이썬 자료형 확인 type()

(Python type()에서 넘어옴)

1 개념[ | ]

Check Python data type
Python type()
  • Python에서는 데이터타입을 확인 하기 위해서는 type() 을 사용하여 확인

2 Python 3[ | ]

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

3 Python 2[ | ]

print(type(123))   # <type 'int'>
print(type(12.3))  # <type 'float'>
print(type('123')) # <type 'str'>
print(type({})) # <type 'dict'>
print(type([])) # <type 'list'>
print(type('안녕'))  # <type 'str'>
print(type(u'안녕')) # <type 'unicode'>
print( type(123) )       # <type 'int'>
print( type(type(123)) ) # <type 'type'>
print( str(type(123)) )  # <type 'int'>
print( "The type is " + str(type(123)) ) # The type is <type 'int'>

4 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}