Home > Blockchain >  why it is showing str type even after typecasting?
why it is showing str type even after typecasting?

Time:04-16

Code:

a,b = input("enter two values").split(",")
int(a)
int(b)
print(type(a))
print(type(b))

Output

enter two values 13 ,14
13 ,14
<class 'string'>
<class 'string'>

CodePudding user response:

The int operation returns a new value, it doesn't change the type of the variable you pass to it. You're not reassigning the original variables, so those values don't change types.

Try this:

a,b = input("enter two values").split(",")
a = int(a)
b = int(b)
print(type(a))
print(type(b))

CodePudding user response:

This is because you're not changing the variable type properly, here is my code

a,b = input("enter two values").split(",")
a,b = int(a), int(b)
print(type(a))
print(type(b))
  • Related