Align and Pad Columns with format()

Medium ⏱ 12 min 54% acceptance ★★★★☆ 4.3
Write format_row(label, value) that uses the str.format() method (not an f-string) to return label left-aligned in a 15-character field immediately followed by value right-aligned in a 10-character field.

Examples

Example 1
Input
label = 'Revenue', value = 45230
Output
'Revenue             45230'
Explanation

'Revenue' padded to 15 chars with trailing spaces, then '45230' right-aligned in 10 chars.

Constraints

  • len(label) <= 15

Topics

StringsString Formatting

Companies

DeloitteCognizant

Hints

Hint 1

`"{:<15}{:>10}".format(label, value)` handles both fields in one call.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.