728x90

파이썬은 변수를 선언할때 타입을 선언하지 않아도 알아서 추론해주지만 분명 타입은 존재합니다.
그러한 타입중 number형에 대해서 알아보려합니다.
정수형
# 정수형
a = 100
print(a)
print(type(a))

a에 100을 대입하고 출력하면 100이 출력이 됩니다.
파이썬에서는 type()으로 해당 객체의 타입을 알수있습니다.
또한 파이썬에서는 모든 변수는 객체 즉 class입니다!
실수형
# 실수형
b = 100.1
print(b)
print(type(b))

자바에서는 실수형의 기본 타입으로 double을 사용하지만 파이썬에서는 float로 출력이 되네요.
파이썬에서의 모든 변수는 class이기 때문에 class 'float'라고 출력이 됩니다.
2진수(0b)
# 2진수(0b)
c = 0b1111
print(c)

0b뒤에 숫자를 붙이면 2진수로 인식합니다.
이런 2진수를 10진수로 바꾸어 출력해줍니다.
8진수(0o)
# 8진수(0o)
d = 0o77
print(d)

0o뒤에 오는 숫자는 8진수입니다.
16진수(x)
# 16진수(0x)
e = 0xff
print(e)

0x뒤에 오는 숫자는 16진수입니다.
728x90
'Python > Python' 카테고리의 다른 글
[Python] list(리스트) (0) | 2022.04.27 |
---|---|
[Python] 문자열(string) (0) | 2022.04.26 |
[Python] 변수(variable)와 타입(type) (0) | 2022.04.24 |
[Python] 파이썬에서 사용할 수 있는 주석 (0) | 2022.04.23 |
[Python] 파이썬 설치하기! (0) | 2022.04.22 |