Nitin
Nitin

Reputation: 2874

Strange symbols in Python

I am working on Python and have been experimenting with the escape sequences \v and \f. The output seems to be giving strange symbols where I put these 2 escape sequences. I am not able to post the image of the output due to some spam prevention policies by the website. Could someone give any ideas as to what could be the problem. Thanks.

Upvotes: 3

Views: 4335

Answers (1)

mechanical_meat
mechanical_meat

Reputation: 169434

Escape-sequences are documented here:
http://docs.python.org/reference/lexical_analysis.html#string-literals

\v is a vertical tab
\f is a form feed

If you print them in the REPL you get the hexadecimal value (0c).
Example:

>>> '\f'
'\x0c'

As with some other conventions, the \x escape-sequence is inherited from C.
Reference: http://www.python.org/dev/peps/pep-0223/

Aside:
If you prefer the ASCII code to the hex code you can use ord():

>>> ord('\f')
12

Upvotes: 4

Related Questions