How To Generate The String 'x000' In Python?
Solution 1:
A string literal is the text you type into a program that python compiles into a str
object. Python treats the backslash character \
specially - it allows you to enter characters that are not on the keyboard. But sometimes you need the backslash so it can be unescaped with \\
. When displaying strings, python has both repr
and str
versions of the string. repr
gives you the literal sting version, while str
gives you the real string. Its a bit confusing that "literal" is literally not the string. If you escape the string and print it, you'll see the real characters.
>>>remove_string = '\\000'>>>remove_string
'\\000'
>>>print(remove_string)
\000
You also used raw strings. Prepending with "r" tells python to stop using the backslash as a special string in a string literal. However, if you take the repr of that string later, you'll still get the special string literal represenation. No, problem though, because the string is correct.
>>>remove_string = r'\000'>>>remove_string
'\\000'
>>>print(remove_string)
\000
Post a Comment for "How To Generate The String 'x000' In Python?"