What is "\00" in Python?
What does "\00" mean in Python? To learn more about this, I tried following:
- When I assign
d="\00"
and callprint d
, nothing displays on the screen. - I also tried assigning
d
to a string with extra spacing b开发者_高级运维etween and at the end and then calledd.replace("\00", "")
, but no result was evident.
What does d.replace("\00","")
do? Will it merely look for this particular string "\00" and replace it with an empty string?
In Python 2, when a number starts with a leading zero, it means it's in octal (base 8). In Python 3 octal literals start with 0o
instead. 00
specifically is 0.
The leading \
in \00
is a way of specifying a byte value, a number between 0-255. It's normally used to represent a character that isn't on your keyboard, or otherwise can't be easily represented in a string. Some special characters also have non-numeric "escape codes", like \n
for a newline.
The zero byte is also known as the nul byte or null byte. It doesn't display anything when printed -- it's null.
See http://www.ascii.cl/ for ASCII character codes.
Yes, replace
will still work with it, it just has no meaning as a display character.
It's sometimes used for other purposes, see http://en.wikipedia.org/wiki/Null_character.
The backslash followed by a number is used to represent the character with that octal value. So your \00
represents ASCII NUL.
精彩评论