파이썬 자료형 중 논리형, 숫자형(정수, 실수), 문자(열)형에 대해 알아봅니다.
효율적인 메모리 사용을 위해서 데이터를 여러 형태로 나누어 구분한 것.
bool
True
or False
1
과 0
만을 이용하는 방식.1
은 True
, 0
은 False
로 표현.int
1234
float
12.34
float
으로 표기.str
"가나다라"
True
, False
, 숫자 등도 따옴표(" "
or ' '
)로 묶이면 문자(열)로 인식.type()
[예시 입력]
a = 123
b = 1.23
c = True
d = False
e = "123"
f = "1.23"
g = "True"
h = "False"
i = "가나다라"
print(type(a), a)
print(type(b), b)
print(type(c), c)
print(type(d), d)
print(type(e), e)
print(type(f), f)
print(type(g), g)
print(type(h), h)
print(type(i), i)
[예시 출력]
<class 'int'> 123
<class 'float'> 1.23
<class 'bool'> True
<class 'bool'> False
<class 'str'> 123
<class 'str'> 1.23
<class 'str'> True
<class 'str'> False
<class 'str'> 가나다라
숫자형 데이터 타입에는 정수(int
)와 실수(float
) 외에 복소수(Complex Number: complex
)도 있으나 이번 글에서는 생략했다. 실사용을 해본 적이 없어서 따로 공부하지 않았지만, 직접 사용하게 되면 추후에 추가해야겠다.