본문 바로가기
파이썬

파이썬 " 'float'개체를 암시 적으로 str로 변환 할 수 없습니다."

by º기록 2020. 12. 20.
반응형
>>> def main():
        fahrenheit = eval(input("Enter the value for F: "))
        celsius = fahrenheit - 32 * 5/9
        print("The value from Fahrenheit to Celsius is " + celsius)
>>> main()
Enter the value for F: 32
Traceback (most recent call last):  
  File "<pyshell#73>", line 1, in <module>
    main()
  File "<pyshell#72>", line 4, in main
    print("The value from Fahrenheit to Celsius is " + celsius)
TypeError: Can't convert 'float' object to str implicitly"

 

해결 방법

 

floats 는 암시 적으로 문자열로 변환 될 수 없습니다. 명시 적으로해야합니다.

print("The value from Fahrenheit to Celsius is " + str(celsius))

그러나 형식 을 사용하는 것이 좋습니다.

print("The value from Fahrenheit to Celsius is {0}".format(celsius))

 

참조 페이지 https://stackoverflow.com/questions/22397261

 

 

반응형

댓글