如何在Python中从字面上打印字符串 [英] How to print a string literally in Python
本文介绍了如何在Python中从字面上打印字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这可能真的很简单,但我找不到它。
this is probably really simple but I can't find it.
我需要打印Python字符串中包含的内容。我正在从串行端口收集数据,我需要知道它是否正在发送CR或CRLF +其他不是ascii的控制代码。
I need to print what a string in Python contains. I'm collecting data from a serial port and I need to know if it is sending CR or CRLF + other control codes that are not ascii.
例如,我说
s = "ttaassdd\n\rssleeroo"
然后我想做的是:
print s
在哪里显示\n\r而不是将其隐藏为转义字符。
Where it would show the \n\r rather than covert them into escape characters.
推荐答案
尝试使用:
print repr(s)
>>> 'ttaassdd\n\rssleeroo'
这篇关于如何在Python中从字面上打印字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文