Python - 문제 미리보기

문제 1859

medium
숫자 타입 변환에서 빈칸에 들어갈 올바른 함수는?
x = 1        # int
y = 2.8      # float
z = 1j       # complex

a = ______(x)    # int를 float로
b = ______(y)    # float를 int로  
c = ______(x)    # int를 complex로
A. `float`, `int`, `complex`
B. `real`, `integer`, `imaginary`
C. `decimal`, `whole`, `complex`
D. `double`, `round`, `complex`

정답: A



⦁ Python 숫자 타입 변환 함수들:

float() - 실수로 변환:
a = float(x)    # 1 → 1.0
a = float(5)    # 5 → 5.0
a = float("3.14")  # "3.14" → 3.14

int() - 정수로 변환:
b = int(y)      # 2.8 → 2 (소수점 버림)
b = int(3.9)    # 3.9 → 3 (반올림 아님!)
b = int("42")   # "42" → 42

complex() - 복소수로 변환:
c = complex(x)  # 1 → (1+0j)
c = complex(3.5)  # 3.5 → (3.5+0j)
c = complex(2, 3)  # 2+3j

💡 학습 팁

이 문제를 포함한 Python 과목의 모든 문제를 순차적으로 풀어보세요. 진행상황이 자동으로 저장되어 언제든지 이어서 학습할 수 있습니다.