简体   繁体   English

Int 到 String 类型的转换

[英]Int to String type conversion

I am a beginner to Python.Below is the code which i tried yesterday我是 Python 的初学者。下面是我昨天尝试的代码

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?结果是 95 而不是 5243。我想知道如果我将这些变量转换为字符串,那么为什么要以数学方式添加它们?

what you have done is, you are not re-assigning the casted value to x and y.您所做的是,您没有将转换后的值重新分配给 x 和 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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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