A better way to do this is using the netaddr library. as shown in this post Better way of formatting mac addresses in python
I have a large set of shell script that I had written in shell, which I have been converting to python based scripts. I found using python I could better extend my scripts and reuse code. I also appreciate that python is a full object oriented programming language, with a very powerful set of standard libraries and many optional third party libraries.