# Chapter 23: Library Support for Numbers and Character Data¶

## Example tclassify.c, Page 613¶

In [38]:
import string
print " alnum alpha digit graph lower print punct space upper xdigit"
p="azAZ0 !\t"
p1=list(p)
for i in p1:
listt=[" "]*10
print i,
if(i.isalnum()):
listt[0]=" X"
if(i.isalpha()):
listt[1]=" X"
if(i.isdigit()):
listt[2]=" X"
if(i.isspace()!=True):
listt[3]=" X"
if(i.islower()):
listt[4]=" X"
if(i in string.printable):
listt[5]=" X"
if(i in string.punctuation):
listt[6]=" X"
if(i.isspace()):
listt[7]=" X"
if(i.isupper()):
listt[8]=" X"
if(i in string.hexdigits):
listt[9]=" X"
print listt

 alnum alpha digit graph lower print punct space upper xdigit
a [' X', ' X', ' ', ' X', ' X', ' X', ' ', ' ', ' ', ' X']
z [' X', ' X', ' ', ' X', ' X', ' X', ' ', ' ', ' ', ' ']
A [' X', ' X', ' ', ' X', ' ', ' X', ' ', ' ', ' X', ' X']
Z [' X', ' X', ' ', ' X', ' ', ' X', ' ', ' ', ' X', ' ']
0 [' X', ' ', ' X', ' X', ' ', ' X', ' ', ' ', ' ', ' X']
[' ', ' ', ' ', ' ', ' ', ' X', ' ', ' X', ' ', ' ']
! [' ', ' ', ' ', ' X', ' ', ' X', ' X', ' ', ' ', ' ']
[' ', ' ', ' ', ' ', ' ', ' X', ' ', ' X', ' ', ' ']


## Example tcasemap.c, Page 615¶

In [1]:
p="aA0!"
pl=list(p)
for i in pl:
print "tolower('%c') is '%c'; "% (i,i.lower()),
print "toupper('%c') is '%c'; "% (i,i.upper())

tolower('a') is 'a';  toupper('a') is 'A';
tolower('A') is 'a';  toupper('A') is 'A';
tolower('0') is '0';  toupper('0') is '0';
tolower('!') is '!';  toupper('!') is '!';

In [ ]: