Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print all characters in a string

Tags:

python

string

Is there a way to print all characters in python, even ones which usually aren't printed?

For example

>>>print_all("skip
 line")
skip\nline
like image 717
Ester Lin Avatar asked Mar 11 '23 07:03

Ester Lin


1 Answers

Looks like you want repr()

>>> """skip
... line"""
'skip\nline'
>>>
>>> print(repr("""skip
... line"""))
'skip\nline'
>>> print(repr("skip    line"))
'skip\tline

So, your function could be

print_all = lambda s: print(repr(s))

And for Python 2, you need from __future__ import print_function

like image 192
OneCricketeer Avatar answered Mar 15 '23 14:03

OneCricketeer