Subtracting str from int


#1

my_variable=10;
print my_variable;
print my_variable-a;

this is my code

the ans is below

10
4
None

if i replace** a** with any other variable_name(like b,c,d,.....) then the code throws an error saying unsupported datatype str and int

How is this possible


#2

is that all your code? a must be a variable, otherwise you get a undefined error.


#3

I don't think that's what it says.

It likely says that some operator isn't supporting those operand types, and indeed it makes no sense to subtract a number from a string or the other way around.


#4

Presumably a equals 6 somewhere in the code for you to get that answer.

Any other name (b,c,d,...) must first be defined as a number before you can subtract it from another number.
e.g. for the computer to understand my_variable-b, it needs to understand that b=5 or b=3 etc.

If you don't have a number for a variable name then it won't work.

If you want to change a to b then make sure you find the part of the code which says a=6 and change that to b=6 as well.

I hope this helps!