| 예시 | 참고 | ||
|---|---|---|---|
| 정수 | int | -1, 0, 5 |
|
| 실수 | float | -1.5, .25 |
일의 자리가 0인 경우, 일의 자리에 0을 생략할 수 있다. |
| 문자열 | str | 'hello world' |
|
| 불 | bool | True, False |
|
| 리스트 | list | ['string', 123, 1.67] |
자료형을 다른 자료형으로 변환하려면,
자료형() 를
내장 함수인 type() 함수를 사용하여 자료형을 확인할 수 있습니다.
s = 'hello world!'
print(type(s)) # <class 'str'>
i = 123
print(type(i)) # <class 'int'>
f = 1.5
print(type(f)) # <class 'float'>