简体   繁体   中英

how do I extract a input string literal containing escape sequences like \a,\16 as a raw string?

I want to extract the following input text as raw string but for both r''+ string, repr(string) \a,\1 are getting replaced with \x07,\x01. Will appreciate some help

input_txt = 'ab\a\1'
t1=r''+input_txt
t2=repr(input_txt)
print(t1)
print(t2)

Raw string is created by prefixing a string literal with 'r' or 'R'.

input_txt = r'ab\a\1'
t1 = input_txt
t2 = repr(input_txt)
print(t1)
print(t2)

In the Python Raw string, we usually write the word within the quotes, and in addition to it, we add the literal 'r' as the prefix to it, and then we assign it to a variable and print that variable. All the Raw strings must contain the literal 'r' at its prefix.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM