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

def mid_letter(letter):
return chr((ord(letter) - ord('a')) // 2 + ord('a'))

>>> >>> mid_letter("l")
'f'

LINKS

--

--

Infrastructure Support Engineer/Technical Writer (snowplow.io) with a passion for Python/writing documentation. More about me: https://pavol.kutaj.com

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Pavol Kutaj

Infrastructure Support Engineer/Technical Writer (snowplow.io) with a passion for Python/writing documentation. More about me: https://pavol.kutaj.com