How about:
astring = 'Hello.' for c in astring: print('\\{:03o}'.format(ord(c)), end='') print()results:
Output:/110/145/154/154/157/056
or use list comprehension[print('\\{:03o}'.format(ord(c)), end='') for c in astring]