int转str python
时间: 2023-11-16 09:05:05 浏览: 33
在 Python 中,可以使用 `str()` 函数将整数转换为字符串。例如:
```python
x = 123
y = str(x)
print(y)
```
输出结果为:
```
'123'
```
如果要将整数转换为带有特定进制的字符串,可以使用 `format()` 方法。例如,将十进制整数转换为二进制字符串:
```python
x = 123
y = "{0:b}".format(x)
print(y)
```
输出结果为:
```
'1111011'
```
其中,`{0:b}` 的意思是将第一个参数 `x` 转换为二进制字符串。其他进制的转换也可以类似地使用 `format()` 方法。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)