【问题标题】:Print out carriage return or new line characters打印出回车符或换行符
【发布时间】:2023-02-21 00:38:38
【问题描述】:

你好,我有一个看起来像这样的字符串

This is a test string This is the second line 我正在尝试打印出这两行并查看实际的 \r 或 \n 字符

所以它会像这样输出

This is a test string\n This is the second line\n

我只试过 print(string variable) 但这给了我没有“\n”或“\r”的字符串

【问题讨论】:

标签: python


【解决方案1】:

根据您的目标,我可以想到两种方法。

s="one
two
three

xour
f"
print(s.encode()) # print not a string but a bytes array, (b'...') containing the bytes encoding the string. 
print(s.__repr__()) # print the same thing the interactive interpreter shows when you just type `s` on a line. 

【讨论】:

    猜你喜欢
    • 2021-07-05
    • 1970-01-01
    • 1970-01-01
    • 2013-04-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-28
    相关资源
    最近更新 更多