Try to 개발자 EthanJ의 성장 로그

Python Data type (int, float) 파이썬 자료형 (정수, 실수) 본문

CS & DS/Basic Python with Data Crawling

Python Data type (int, float) 파이썬 자료형 (정수, 실수)

EthanJ 2022. 10. 4. 17:38

Python Data type (int, float) 파이썬 자료형 (정수, 실수)

Why 숫자형부터 시작?

  • 컴퓨터가 이해할 수 있는 단 하나의 언어: 기계어(machine language) with 0, 1

> 숫자형

- 종류

  • 정수: 0, 양의 정수, 음의 정수
  • 실수: 소수점을 포함하는 숫자
  • 8진수 (0o or 0O로 시작): e.g. 0o34, 0o25
  • 16진수 (0x로 시작): e.g. 0x2A, 0xFF
  • 2진수 (0b로 시작): e.g. 0b10, 0b11

- 8bit == 1byte

1) 정수형 (int)

#양수, 음수, 0
a = 10
b = -20
c = 0
# 출력 함수 > print(변수명)
print(a)
10

 

# print(string) > string " "안의 내용 출력
print("a")
a

 

print("Hello world")
Hello world

 

 

# data type을 확인하는 함수 > type()
type(a)
int

 

type(b)
int

 

type(c)
int

 

 

2) 실수형 (float)

# 실수 data type == float
a = 1.3
b = -2.4
c = 0.0
# 실수 타입 확인
type(a)
float

 

type(b)
float

 

type(c)
float

 

 

# 0 vs 0.0
print(type(0), type(0.0))
<class 'int'> <class 'float'>

 

# 정수와 실수가 다른 숫자로 인식되는 이유: 2의 보수(정수) vs floating point(실수)
Comments