繁体   English   中英

"Python 替换字符串中的 \\n"

[英]Python replace \n in a string

如何在我的字符串中替换 \\n? 例如: test = Hello\\nHello\\nHello 如果我尝试 test = test.replace("","") 它将不起作用,因为 \\n 自动是一个新行,所以有什么技巧可以做到这一点?

所以再次 test = test.replace("","") 不起作用

你的问题不是很清楚,但根据我的理解你应该写:

test = "Hello\nHello\nHello"
test = test.replace("\n", "")

你可以直接做

test = 'Hello\nHello\nHello'
result = test.replace('\n', '')
print(result)

HelloHelloHello

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM