简体   繁体   中英

Int to String type conversion

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?

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM