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
推荐的帖子
Read input as an integer in Python
在Python中将输入读取为整数
Read input as a float in Python
在Python中以浮点形式读取输入
Parse a string to float in Python (float() function)
解析要在Python中浮动的字符串(float()函数)
How do you read from stdin in Python?
您如何从Python的stdin中读取信息?
Asking the user for integer input in Python | Limit the user to input only integer value
要求用户在Python中输入整数| 限制用户仅输入整数值
Asking the user for input until a valid response in Python
要求用户输入直到Python中的有效响应
Input a number in hexadecimal format in Python
在Python中以十六进制格式输入数字
Input a number in octal format in Python
在Python中以八进制格式输入数字
Input a number in binary format in Python
在Python中以二进制格式输入数字
How to get the hexadecimal value of a float number in python?
如何在python中获取浮点数的十六进制值?
Convert a float value to the string using str() function in Python
使用Python中的str()函数将浮点值转换为字符串
Input and Output Operations with Examples in Python
使用Python中的示例进行输入和输出操作
Taking multiple inputs from the user using split() method in Python
使用Python中的split()方法从用户获取多个输入
Fast input / output for competitive programming in Python
快速输入/输出,可在Python中进行有竞争力的编程
Precision handling in Python
Python中的精确处理
Python print() function with end parameter
带有结束参数的Python print()函数
翻译自: https://www.includehelp.com/python/convert-an-integer-value-to-the-string-using-str-function-in-python.aspx
python整数转换字符串