1 개념[ | ]
- Check Python data type
- Python type()
- Python에서는 데이터타입을 확인 하기 위해서는 type() 을 사용하여 확인
2 Python 3[ | ]
Python
Copy
print(type(123)) # <class 'int'>
print(type(12.3)) # <class 'float'>
print(type('123')) # <class 'str'>
Loading
Python
Copy
print(type([])) # <class 'list'>
print(type([1, 2, 3, 4, 5])) # <class 'list'>
Loading
Python
Copy
print(type({})) # <class 'dict'>
print(type(())) # <class 'tuple'>
Loading
Python
Copy
print(type(None)) # <class 'NoneType'>
Loading
Python
Copy
print(type('안녕')) # <class 'str'>
print(type(u'안녕')) # <class 'str'>
Loading
- → Python 3에서는 문자열이 항상 유니코드로 처리되므로 u 표기가 필요없다.
3 Python 2[ | ]
Python
Copy
print(type(123)) # <type 'int'>
print(type(12.3)) # <type 'float'>
print(type('123')) # <type 'str'>
Python
Copy
print(type({})) # <type 'dict'>
print(type([])) # <type 'list'>
Python
Copy
print(type('안녕')) # <type 'str'>
print(type(u'안녕')) # <type 'unicode'>
Python
Copy
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 같이 보기[ | ]
편집자 Jmnote
로그인하시면 댓글을 쓸 수 있습니다.