To find the ASCII value of a character use the ord() function.
To get a character from it's ASCII value use the chr() function.
Here is a program to get the list of all characters along with their values:
# program to print the list of characters and their ASCII values
for value in range(0, 255):
print "ASCII Value:", value, "\t", "Character:", chr(value), "\n"
Here is another simple ASCII encoding-decoding program:
# Convertion from text to ASCII codes
message = raw_input("Enter message to encode: ")
print "Decoded string (in ASCII):"
for ch in message:
# Convertion from ASCII codes to text
message = raw_input("Enter ASCII codes: ")
decodedMessage = ""
for item in message.split():
decodedMessage += chr(int(item))
print "Decoded message:", decodedMessage
Hope you got a clear understanding of how to convert between text and ASCII code.