How to only get \n for newline without the single quotes?

Wildman best_lay at yahoo.com
Sat Feb 24 13:45:44 EST 2018


On Sat, 24 Feb 2018 11:41:32 -0600, Peng Yu wrote:

> I would like to just get the escaped string without the single quotes.
> Is there a way to do so? Thanks.
> 
>>>> x='\n'
>>>> print repr(x)
> '\n'

Python 3.5.3 (default, Jan 19 2017, 14:11:04) 
[GCC 6.3.0 20170118] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> x='/n'
>>> print(repr(x))
'/n'
>>> print(repr(x).strip("'"))
/n
>>> 

Python 2.7.13 (default, Nov 24 2017, 17:33:09) 
[GCC 6.3.0 20170516] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> x='/n'
>>> print repr(x)
'/n'
>>> print repr(x).strip("'")
/n
>>> 

-- 
<Wildman> GNU/Linux user #557453
"There are only 10 types of people in the world...
those who understand Binary... and those who don't."
  -Spike



More information about the Python-list mailing list