Skip to main content

Section 3.10 Character classification

It is often helpful to examine a character and test whether it is upper- or lowercase, or whether it is a character or a digit. The string module provides several constants that are useful for these purposes. One of these, string.digits is equivalent to “0123456789”. It can be used to check if a character is a digit using the in operator.
The string string.ascii_lowercase contains all of the ascii letters that the system considers to be lowercase. Similarly, string.ascii_uppercase contains all of the uppercase letters. string.punctuation comprises all the characters considered to be punctuation. Run the following:
For more information consult the string module documentation (see Global Module Index
 1 
http://docs.python.org/py3k/py-modindex.html
).

Note 3.10.1.

More About ASCII
ASCII is abbreviated from American Standard Code for Information Interchange. As computers store data in numeric values, for each character (words, punctuations, etc) a specific number is assigned to represent it. This process is called character encoding. In order to exchange informations between different computers, a set of standards were needed, from which ASCII was born.
ASCII contains 128 characters, where each character is assigned with a specific number. For instance uppercase alphabet starts from A = 65, while lowercase alphabet starts from a = 97 and continues as b=98, c=99, so on. Due to its limited size, this standard is replaced by Unicode which contains thousands of characters, however still useful to understand and work on encoding.

Note 3.10.2.

This workspace is provided for your convenience. You can use this activecode window to try out anything you like.
You have attempted of activities on this page.