'why it is showing str type even after typecasting?
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'>
Solution 1:[1]
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))
Solution 2:[2]
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))
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Bill the Lizard |
| Solution 2 | Karam Helmi |
