How to do calculations on alphabet in Python
The aim of this page📝 is to share how a simple pattern of “programming alphabet” combining ord()
, chr()
and doing some math in between
for example, given a letter, return another letter that is in the middle between ‘a’ and the given letter
- Example: if the input is
c
, I want to receive theb
def mid_letter(letter):
return chr((ord(letter) - ord('a')) // 2 + ord('a'))
>>> >>> mid_letter("l")
'f'