Skip to content Skip to sidebar Skip to footer

How To Print A String Literally In Python

this is probably really simple but I can't find it. 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

Solution 1:

Try with:

printrepr(s)
>>> 'ttaassdd\n\rssleeroo'

Solution 2:

Saving your string as 'raw' string could also do the job.

(As in, by putting an 'r' in front of the string, like the example here)

    >>> s = r"ttaassdd\n\rssleeroo"
    >>> print s
    ttaassdd\n\rssleeroo

Post a Comment for "How To Print A String Literally In Python"