📌  相关文章
📜  使用 replace() 方法从字符串中删除换行符 - Python 代码示例

📅  最后修改于: 2022-03-11 14:46:59.207000             🧑  作者: Mango

代码示例1
# Python code to remove newline character from string using replace() method

text = "A regular \n expression is a sequence \n of characters\n that specifies a search\n pattern. "
print(text.replace('\n', ''))

my_list = ["Python\n", "is\n", "Fun\n"]
new_list = []

print("Original List: ", my_list)

for i in my_list:
    new_list.append(i.replace("\n", ""))
print("After removal of new line ", new_list)