Thursday, March 10, 2011

Mar. 10

When working with the string module, I realized that the expression dir means directory.
>>>import string
>>>dir(string)

['Formatter', 'Template', '_TemplateMetaclass', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '_float', '_idmap', '_idmapL', '_int', '_long', '_multimap', '_re', 'ascii_letters', 'ascii_lowercase', 'ascii_uppercase', 'atof', 'atof_error', 'atoi', 'atoi_error', 'atol', 'atol_error', 'capitalize', 'capwords', 'center', 'count', 'digits', 'expandtabs', 'find', 'hexdigits', 'index', 'index_error', 'join', 'joinfields', 'letters', 'ljust', 'lower', 'lowercase', 'lstrip', 'maketrans', 'octdigits', 'printable', 'punctuation', 'replace', 'rfind', 'rindex', 'rjust', 'rsplit', 'rstrip', 'split', 'splitfields', 'strip', 'swapcase', 'translate', 'upper', 'uppercase', 'whitespace', 'zfill']
The above is the full list of the items in the string module.
When i ask to see all the digits I get from the string module I get:
>>> print string.digits
0123456789
Not surprising you get all the digits. 
>>> string.find("banana", "na")
2
The out come of this program is 2 because in the word "banana", you will find 2 occurrence of "na". >>> >>>print string.lowercase
abcdefghijklmnopqrstuvwxyz
>>> print string.uppercase
ABCDEFGHIJKLMNOPQRSTUVWXYZ
>>> print string.digits
0123456789
When working with the string module, I've noticed that it has many possible outputs to the program. Basically this program has self explanatory, such as lowercase, uppercase, and digits. 
>>> print string.whitespace
When you put this into the terminal you get just a few open lines of blank space.

No comments:

Post a Comment