The Artima Developer Community
Sponsored Link

Python Buzz Forum
A useful octal escape sequence

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Thomas Guest

Posts: 236
Nickname: tag
Registered: Nov, 2004

Thomas Guest likes dynamic languages.
A useful octal escape sequence Posted: Aug 9, 2009 1:34 PM
Reply to this message Reply

This post originated from an RSS feed registered with Python Buzz by Thomas Guest.
Original Post: A useful octal escape sequence
Feed Title: Word Aligned: Category Python
Feed URL: http://feeds.feedburner.com/WordAlignedCategoryPython
Feed Description: Dynamic languages in general. Python in particular. The adventures of a space sensitive programmer.
Latest Python Buzz Posts
Latest Python Buzz Posts by Thomas Guest
Latest Posts From Word Aligned: Category Python

Advertisement

Previously I grumbled about octal integer literals, suggesting:

  1. they aren’t much use, not when you’ve got hexademical and binary literals.
  2. they’re risky. As Doug Napoleone noted in a comment, 011 is all too easily read as eleven rather than nine.

Python 3 attempts to patch the readability issue: octal nine must be written as 0o11 or 0O11. Choose your fonts with care, O and 0 look similar!

>>> 0o11, 0O11
(9, 9)

Octal numbers can also appear in escape sequences embedded in string and bytes literals. The syntax hasn’t changed for Python 3 and the rules are as in C: the escape sequence \OOO embeds a character/byte with octal value OOO. Up to three octal digits are allowed in an octal escape sequence.

Smart mollusc Smart mollusc Smart mollusc

Like octal integers, these octal escape sequences may appear to be of limited use — a syntactic oddity rarely seen in the wild — but in fact there’s one particular use case which is so common we don’t even notice it.

char const terminator = '\0';

Read: A useful octal escape sequence

Topic: A useful octal escape sequence Previous Topic   Next Topic Topic: Hello world!

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use