Python Forum
Character Definition Like ASCII
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Character Definition Like ASCII
#1
hi. i want to know is there anything like ASCII character definition in python?
Reply
#2
Hm, what do you mean with character definition?

Try to import the module string and look for the content.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply
#3
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'
>>>
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  mutable argument in function definition akbarza 1 426 Dec-15-2023, 02:00 PM
Last Post: deanhystad
  error occuring in definition a class akbarza 3 636 Nov-26-2023, 09:28 AM
Last Post: Yoriz
  determine parameter type in definition function akbarza 1 550 Aug-24-2023, 01:46 PM
Last Post: deanhystad
Question UnicodeEncodeError: 'ascii' codec can't encode character u'\xe8' in position 562: ord ctrldan 23 4,615 Apr-24-2023, 03:40 PM
Last Post: ctrldan
  [split] Explain the python code in this definition Led_Zeppelin 1 711 Jan-13-2023, 10:20 PM
Last Post: deanhystad
  Explain the python code in this definition Led_Zeppelin 1 1,060 Oct-27-2022, 04:04 AM
Last Post: deanhystad
  UnicodeEncodeError: 'ascii' codec can't encode character '\xfd' in position 14: ordin Armandito 6 2,645 Apr-29-2022, 12:36 PM
Last Post: Armandito
  meaning of -> syntax in function definition DrakeSoft 5 1,879 Apr-09-2022, 07:45 AM
Last Post: DrakeSoft
  Not including a constructor __init__ in the class definition... bytecrunch 3 11,527 Sep-02-2021, 04:40 AM
Last Post: deanhystad
  [solved] unexpected character after line continuation character paul18fr 4 3,296 Jun-22-2021, 03:22 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020