Reputation: 91
I want to subtract two strings like so:
health = "100"
nuke = "50"
health = health - nuke
print(health)
It is meant to assign the new value '50' as the health but when i do this i get: TypeError: unsupported operand type(s) for -: 'str' and 'str'
Upvotes: 1
Views: 55
Reputation: 91
health = 100
nuke = 50
health = health - nuke
print(health)
This keeps the code nice and tidy instead of having to change things into intergers
Upvotes: 0
Reputation: 33651
Python is not js, you cannot subtract string from string. Convert them to number:
print(int(health) - int(nuke))
Upvotes: 1