How do I get the ASCII values for a word

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Jasmine Thomas

    How do I get the ASCII values for a word

    In my program, I have to get 2 letter from the first name. How do I get the asc values for those 2 letters.
    *the letters change every time so I can't just use... for ex. ja
    ord('j')
    ord('a')
    how would i get values for any of the letters no matter what they are??
  • dwblas
    Recognized Expert Contributor
    • May 2008
    • 626

    #2
    You would pass each of the first two letters to ord. From your example, there is no way to tell anything more, but generally speaking it is simpler to work with lists instead of strings.
    Code:
    first_letter = "A"
    second_letter = "b"
    print first_letter, ord(first_letter), second_letter, ord(second_letter)

    Comment

    Working...