Python Forum

Full Version: Character Definition Like ASCII
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
hi. i want to know is there anything like ASCII character definition in python?
Hm, what do you mean with character definition?

Try to import the module string and look for the content.
If one were to take your question literally, the answer would be no, Python does not define the ASCII character set, rather it adheres to the ASCII character set definition. Basically, it is the numerical representation of printable and certain control characters between decimal 0 and 127 and hearkens back to the days of the teletype.  This definition persists even today, whether you are using code pages or Unicode.

Python does provide several ways of working with the ASCII set, for example:

>>> chr(120)
'x'
>>> ord('x')
120
As @DeaD_EyE pointed out, the "string" library also has several options, for example:

>>> string.ascii_letters
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
>>> string.printable
'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~ \t\n\r\x0b\x0c'
>>>