jd.
jd.

Reputation: 4773

str.format() -> how to left-justify

>>> print 'there are {0:10} students and {1:10} teachers'.format(scnt, tcnt)
there are        100 students and         20 teachers

What would be the code so that the output became:

there are 100        students and 20         teachers

Thanks.

Upvotes: 11

Views: 12915

Answers (1)

Eli Courtwright
Eli Courtwright

Reputation: 192921

print 'there are {0:<10} students and {1:<10} teachers'.format(scnt, tcnt)

While the old % operator uses - for alignment, the new format method uses < and >

Upvotes: 23

Related Questions