NaderBesada NaderBesada - 8 months ago 85
Python Question

TypeError: Can't convert 'int' object to string implicitly

title = link.string
amount = title.strip().lstrip("$")

check = "True"
print(amount + 30) #This doesnt work
except ValueError:
check = "False"

I dont know what im doing wrong any help will be appreciated

Print(type(float(amount + 3)))
TypeError: Can't convert 'int' object to str implicitly

Process finished with exit code 1


If the variable amount comes from a lstrip result, that means that the type of amount is str. So, given this, the sentence

amount + 30

will return an exception. You should parse amount before trying to sum a number:

float(amount) + 30

The exception in Python 3 is:

TypeError: Can't convert 'int' object to str implicitly

But in Python 2 is:

TypeError: cannot concatenate 'str' and 'int' objects

Your sentence:

print(amount + 30)

first resolves

amount + 30

then takes the results and tye to print it. The error is before printing it, when adding. Python doesn't parse the text exlicitl in that case.