Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions

  




 

 

String Modules

There is an older module named string. Almost all of the functions in this module are directly available as methods of the string type. The one remaining function of value is the maketrans function, which creates a translation table to be used by the translate method of a string. Beyond that, there are a number of public module variables which define various subsets of the ASCII characters.

maketrans( from , to ) → string

Return a translation table (a string 256 characters long) suitable for use in string.translate. The strings from and to must be of the same length.

The following example shows how to make and then apply a translation table.

>>> 
from string import maketrans

>>> 
t= maketable("aeiou","xxxxx")

>>> 
phrase= "now is the time for all good men to come to the aid of their party"

>>> 
phrase.translate(t)

'nxw xs thx txmx fxr xll gxxd mxn tx cxmx tx thx xxd xf thxxr pxrty'
            

More importantly, this module contains a number of definitions of the characters in the ASCII character set. These definitions serve as a central, formal repository for facts about the character set. Note that there are general definitions, applicable to Unicode character setts, different from the ASCII definitions.

ascii_letters

The set of all letters, essentially a union of ascii_lowercase and ascii_uppercase.

ascii_lowercase

The lowercase letters in the ASCII character set: 'abcdefghijklmnopqrstuvwxyz'

ascii_uppercase

The uppercase letters in the ASCII character set: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

digits

The digits used to make decimal numbers: '0123456789'

hexdigits

The digits used to make hexadecimal numbers: '0123456789abcdefABCDEF'

letters

This is the set of all letters, a union of lowercase and uppercase, which depends on the setting of the locale on your system.

lowercase

This is the set of lowercase letters, and depends on the setting of the locale on your system.

octdigits

The digits used to make octal numbers: '01234567'

printable

All printable characters in the character set. This is a union of digits, letters, punctuation and whitespace.

punctuation

All punctuation in the ASCII character set, this is '!"#$%&\'()*+,-./:;<=>[email protected][\\]^_`{|}~'

uppercase

This is the set of uppercase letters, and depends on the setting of the locale on your system.

whitespace

A collection of characters that cause spacing to happen. For ASCII this is '\t\n\x0b\x0c\r '


 
 
  Published under the terms of the Open Publication License Design by Interspire