我有是个字符串 你好 他好 我好 大家好 ,t通过循环我把他们拼接成 "你好","他好","我好","大家好",python实现代码这么写
时间: 2023-06-28 22:14:57 浏览: 75
可以通过对字符串进行split()和join()操作来实现:
```
s = "你好 他好 我好 大家好"
lst = s.split()
result = ['"' + i + '"' for i in lst]
result_str = ','.join(result)
print(result_str)
```
输出结果为:
```
"你好","他好","我好","大家好"
```
这里利用了列表推导式将字符串拼接成所需的格式。
阅读全文
相关推荐
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![txt](https://img-home.csdnimg.cn/images/20241231045021.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![txt](https://img-home.csdnimg.cn/images/20241231045021.png)
![txt](https://img-home.csdnimg.cn/images/20241231045021.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231045021.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045021.png)
![-](https://img-home.csdnimg.cn/images/20241231045021.png)
![-](https://img-home.csdnimg.cn/images/20241231045021.png)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231045021.png)