| Tip 27 | Discover All Characters in One Place |
★2.7, 3.4+
Sometimes, you need to check whether a character belongs to one of
the character classes, such as letters, digits, white spaces, and
the like. You could exercise your brain and try to remember all
English letters (or some obscure printable characters), but why, if
Python comes with the module string? The module
is very compact and provides nine strings that contain characters
by class:
| => | 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' |
| => | 'abcdefghijklmnopqrstuvwxyz' |
| => | 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' |
| => | '0123456789abcdefABCDEF' |