python int to str
时间: 2023-09-07 15:15:51 浏览: 48
To convert an integer to a string in Python, you can use the `()` function. Here's an example:
```python
num = 42
str_num = str(num)
print(str_num) # Output: "42"
```
In the above code, the `str()` function is used to convert the integer `num` to a string, which is then assigned to the variable `str_num`. Finally, the converted string is printed.
相关问题
python int float str
As an AI language model, I can provide a brief explanation of int, float, and str in Python.
- int: An int is a data type in Python that represents whole numbers. It can be positive or negative, but it cannot have a decimal point. For example, 1, 2, 3, -4, and 0 are all integers.
- float: A float is a data type in Python that represents numbers with decimal points. For example, 1.2, 3.14159, and -0.5 are all floats.
- str: A str is a data type in Python that represents a string of characters, such as letters, numbers, or symbols. Strings are typically enclosed in quotes, either single or double. For example, "hello", 'world', "123", and "!!!" are all strings.
python int转str
在Python中,可以使用`str()`函数将整数转换为字符串。以下是一个例子:
```python
num = 123
str_num = str(num)
print(str_num) # 输出 "123"
```
在这个例子中,我们将整数`123`赋值给变量`num`,然后使用`str()`函数将其转换为字符串,并将结果赋值给变量`str_num`。最后,我们使用`print()`函数输出了转换后的字符串。