Python ProgrammingPython Programming

Python String Padding

lines_of_text = [
    (123, 5487, 'Testing', 'Billy', 'Jones'),
    (12345, 100, 'Test', 'John M', 'Smith')
]

for mytuple in lines_of_text:
    name = '{}, {}'.format(mytuple[4], mytuple[3])
    value = '$' + str(mytuple[1])
    print('{name:<20} {id:>8} {test:<12} {value:>8}'.format(
        name=name, id=mytuple[0], test=mytuple[2], value=value)
    )
Output
Jones, Billy              123 Testing         $5487
Smith, John M           12345 Test             $100