Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
I want to get, given a character, its ASCII value.
ASCII
For example, for the character a, I want to get 97, and vice versa.
a
97
Use chr() and ord():
chr()
ord()
>>> chr(97) 'a' >>> ord('a') 97
Add a comment
>>> ord('a') 97 >>> chr(97) 'a'
ord and chr
print ((ord and chr)(0O041))
Not OP's question, but given the title How can I convert a character to a integer in Python,
How can I convert a character to a integer in Python
int(num) <==> ord(num) - ord('0') str(char) <==> ord(char) - ord('a')
For long string you could use this.
''.join(map(str, map(ord, 'pantente')))
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.