string and text handling his describes the most commonly used python modules related to basic string and text processing the focus of this is on the most common string operations such as processing textregular expression pattern matchingand text formatting codecs the codecs module is used to handle different character encodings used with unicode text / the module is used both to define new character encodings and to process character data using wide range of existing encodings such as utf- utf- etc it is far more common for programmers to simply use one of the existing encodingsso that is what is discussed here if you want to create new encodingsconsult the online documentation for further details low-level codecs interface each character encoding is assigned common name such as 'utf- or 'big the following function is used to perform lookup lookup(encodinglooks up codec in the codec registry encoding is string such as 'utf- if nothing is known about the requested encodinglookuperror is raised otherwisean instance of codecinfo is returned codecinfo instance has the following methodsc encode( [errors] stateless encoding function that encodes the unicode string and returns tuple (byteslength_consumedbytes is an -bit string or byte-array containing the encoded data length_consumed is the number of characters in that were encoded errors is the error handling policy and is set to 'strictby default decode(bytes [errors] stateless encoding function that decodes byte string bytes and returns tuple (slength_consumeds is unicode stringand length_consumed is the number of bytes in bytes that were consumed during decoding errors is the error-handling policy and is set to 'strictby default lib fl ff