Python 和换行符 [英] Python and Line Breaks

查看:48
本文介绍了Python 和换行符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 Python 我知道\n"会中断到字符串中的下一行,但我想要做的是用\n"替换字符串中的每个,".那可能吗?我对 Python 有点陌生.

With Python I know that the "\n" breaks to the next line in a string, but what I am trying to do is replace every "," in a string with a '\n'. Is that possible? I am kind of new to Python.

推荐答案

试试这个:

text = 'a, b, c'
text = text.replace(',', '\n')
print text

对于列表:

text = ['a', 'b', 'c']
text = '\n'.join(text)
print text

这篇关于Python 和换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆