python整数转换字符串_使用Python中的str()函数将整数值转换为字符串

python整数转换字符串

Given an integer value and we have to convert the value to the string using str() function.

给定一个整数值,我们必须使用str()函数将该值转换为字符串。

Python code to convert an integer value to the string value

Python代码将整数值转换为字符串值

# Python code to convert an integer value 
# to the string value

# integer value 
i_value = 12345

# converting to the string value
s_value = str(i_value)

# printing the integer & string values with their types
print("i_value: ", i_value)
print("type(i_value): ", type(i_value))

print("s_value: ", s_value)
print("type(s_value): ", type(s_value))

# another operation by multiplying the value 
print("i_value*4: ", i_value*4)
print("s_value*4: ", s_value*4)

Output

输出量

i_value:  12345
type(i_value):  <class 'int'>
s_value:  12345
type(s_value):  <class 'str'>
i_value*4:  49380
s_value*4:  12345123451234512345

Code explanation:

代码说明:

In the above code i_value is an integer variable contains an integer value, we are converting i_value to the string by using str() function and storing the result in s_value variable. For further verification of the types – we are printing the types of both variables with their values and also printing their 4 times multiplied value.

在上面的代码中, i_value是一个包含整数值的整数变量,我们通过使用str()函数将i_value转换为字符串并将结果存储在s_value变量中。 为了进一步验证类型,我们将同时打印两个变量的类型及其值,并打印其四倍的乘积值。

Recommended posts

推荐的帖子

翻译自: https://www.includehelp.com/python/convert-an-integer-value-to-the-string-using-str-function-in-python.aspx

python整数转换字符串

  • 10
    点赞
  • 23
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值