Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
151 views
in Technique[技术] by (71.8m points)

python 3.x - 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 ?

question from:https://stackoverflow.com/questions/66064224/int-to-string-type-conversion

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...