Exception TypeError: must be str, not int in Python 3
Hello, I just joined a course about learning Python on Codecademy. I wrote a small function as below:
import numpy as np def sumable(a ,b) : return a + b msg = "Total your working days are: " totalWorkingDay = sumable(10, 16) print(str(msg + totalWorkingDay))
I want to learn about function, datatype, input & output in python. But When I was running the code above and got an exception TypeError: must be str, not int.
Traceback (most recent call last): File "main.py", line 10, in <module> print(str(msg + totalWorkingDay)) TypeError: must be str, not int
I know that
str() function will help convert something datatype to string, but it didn't work for me.
I'm using Python 3.9 and Windows 11. Thanks for any idea.
Sornchai Sirichantharat Apr 24 2022
I think you used
str()function is correct but you're wrong way to use it.
print(str(msg + totalWorkingDay))
print(msg + str(totalWorkingDay))
It's will solve for you