Reputation: 45
I am a beginner to Python .Below is the code which i tried yesterday
x=52
y =43
str(x)
str(y)
print(x + y)
The outcome was 95 & not 5243 . I wanted to know thatif I converted those variable into string then why it is adding them mathematically ?
Upvotes: 0
Views: 61
Reputation: 349
what you have done is, you are not re-assigning the casted value to x and y. Refer the code below:
x=52
y =43
x=str(x) # converting x from integer to string and then re-assigning x
y=str(y) # converting y from integer to string and then re-assigning y
print(x + y)
Upvotes: 2