1. Computing

Constants Provided in Python's String Module

By

Many modules in the Python library provide both functions and constants for dealing with various elements of a program. The constants defined in the string module module are:

  • ascii_letters: The set of all letters, both uppercase and lower. It is effectively a combination (or concatenation) of the ascii_lowercase and ascii_uppercase constants (see below). This value is not locale-dependent.
  • ascii_lowercase: The set of lowercase letters 'abcdefghijklmnopqrstuvwxyz'. This value is not locale-dependent and will not change with different locales.
  • ascii_uppercase: The set of uppercase letters 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'. This value is not locale-dependent and will not change.
  • digits: The string of numbers '0123456789'.
  • hexdigits: The string '0123456789abcdefABCDEF'.
  • letters: The concatenation of the lowercase and uppercase constants (see below). The specific value is locale-dependent and will be updated if locale.setlocale() is called.
  • lowercase: A string containing all the lowercase letters. On most systems this is 'abcdefghijklmnopqrstuvwxyz'. Due to the several parts of Python that depend on this definition, it is not adviseable to change the definition of this constant. The specific value is defined when locale.setlocale() is defined. To define it otherwise may lead to "undefined" consequences (and therefore aberrant behaviour on the part of Python).
  • octdigits: The string '01234567'.
  • punctuation: String of ASCII characters that are considered punctuation marks in the locale.
  • printable: String of characters that are considered printable. This is a combination of both letters and whitespace.
  • uppercase: A string containing the uppercase letters. On most systems this is 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'. As with lowercase, re-defining this constant outside of defining locale.setlocale() is not recommended and can lead to unpredictable results.
  • whitespace: A string containing all characters that are considered whitespace (e.g., space, tab, linefeed, return, formfeed, and vertical tab). As with lowercase and uppercase, changing the definition of this constant outside of defining locale.setlocale() is not recommended.
  1. About.com
  2. Computing
  3. Python
  4. Python Library
  5. Python String Module - Constants of Python Strings

©2014 About.com. All rights reserved.