0

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'>
Ch3steR
  • 20,090
  • 4
  • 28
  • 58
  • 2
    In the interest of learning...your original code would work **if** `int(...)` was an [in-place operator](https://stackoverflow.com/questions/4772987/how-are-python-in-place-operator-functions-different-than-the-standard-operator). Since it's not in-place, you need to store the resulting value somewhere. – noslenkwah Apr 15 '22 at 17:17
  • @noslenkwah `int` couldn't really be in-place. You cannot convert a `str` into an `int` inplace (I mean, you could in very hacky ways that would involve modifying the underlying memory, but that would be a recipe for bad things) – juanpa.arrivillaga Apr 15 '22 at 17:42

2 Answers2

2

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))
Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
0

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))