float() 메서드는 숫자 또는 문자열에서 부동 소수점 숫자를 반환합니다.
float() 메서드는 다음을 반환합니다.
# integers
print(float(10))
# floats
print(float(11.22))
# string floats
print(float("-13.33"))
# 공백이 있는 string floats
print(float(" -24.45\n"))
# string float 에러
print(float("abc"))
결과
10.0 11.22 -13.33 -24.45 ValueError: could not convert string to float: 'abc'
© 2022 pinfo. All rights reserved.