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整数转换字符串

    原文作者:cumtb2002
    原文地址: https://blog.csdn.net/cumtb2002/article/details/107803043
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞