Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (50.2k points)
I am currently working with a string variable named 's'. I want to make it a raw string. How can I convert a normal string into a raw string?

1 Answer

0 votes
by (108k points)

I  think you are referring to the str.encode("string-escape") method. Let's say you are having a variable that you want to convert to 'raw string':

a = '\x89'

a.encode('unicode_escape')

'\\x89'

One important piece of information that you can only use string-escape for python 2.x and older versions.

If you are a beginner and want to know more about Python, then do refer to the Python certification.

Related questions

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

30.5k questions

32.6k answers

500 comments

108k users

Browse Categories

...