TIL/Python

파이썬 (2) 숫자 데이터

saramnim 2023. 7. 25. 17:36
728x90
숫자 데이터

자료형(data type)

자료의 형태 - 문자열, 숫자, 논리(true, false)

print(type("hi"))	# <class 'str'>
print(type(10))		# <class 'int'>
print(type(3.14))	# <class 'float'>
print(type(True))	# <class 'bool'>

 

숫자 데이터

정수(int): 소수점이 없다.

실수(float): 소수점이 있다.

a = int(input())	# 정수형으로 입력 받아 349.9 입력 시 349 출력
b = float(input())	# 실수형으로 입력 받아 20 입력 시 20.0 출력
a = 10 // 5	# 몫
b = 10 % 3	# 나머지
c = 2 ** 3	# 제곱
print(a, b, c)	# 2, 1, 8
print(a+b, a-b, a*b, a/b)	# 3, 1, 2, 1.0

나눗셈 연산은 데이터가 실수로 출력된다.

재할당: 데이터를 새로 저장

728x90
반응형