When I try to run:
print "\05"
Nothing is printed.
If I change the 5
after the \0
to another number something weird will often happen. Why is this?
Back slash is an escape sequence to add literal characters to a string by ordinal value. This means you take an ASCII character code and literally insert it into your string. The reason you would do this is that some characters are not valid in source code.
In your case you entered \05
which will be the [enquiry]
character which is not printable and rarely used. Thus python will have printed it but nothing will have happened.
For your reference I include a table of character codes from the wikimedia commons, you can use this to find out what each of the character codes will do.
(File under public domain from Wikimedia commons, can be found here).
However if in the other hand you want to print the literal string \05
you need to escape the bashslash (backslash escapes the next character or characters to cause them to have secondary meanings like inserting by character code as shown above). In your case we need to escape the backslash which changes it from being an escape character into a normal one, we do this with a second bashslash (the first to escape the second). So ultimately your code to do what I think you wanted will be:
print "\\05"
Which will output a literal \05
For ASCII, only characters in the range 0x20
to 0x7E
are printable characters.
The other ASCII characters, have no standard display. For example, the character 0x07
, a.k.a, BEL
, usually generates a beep, but it also might be a visual alarm or something else.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With