What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Use str.ljust() to add spaces on the right, str.rjust() to add them on the left, or str.center() to put them on both sides. For formatted output, use f-string alignment: < for left, > for right, and ^ for center. The requested width is a minimum, not a truncation limit.
Choose the padding direction
These string methods return a new string; they do not change the original string or print anything. The number passed to each method is the minimum total width of the result.
| Goal | Method | Example with "cat" |
Result |
|---|---|---|---|
| Add spaces on the right | ljust(width) |
"cat".ljust(6) |
'cat ' |
| Add spaces on the left | rjust(width) |
"cat".rjust(6) |
' cat' |
| Center with spaces | center(width) |
"cat".center(7) |
' cat ' |
These methods are useful when the operation is specifically about a string. The method names can feel counterintuitive at first: ljust() left-justifies the text, leaving padding on the right; rjust() right-justifies it, leaving padding on the left. See the Python 3.14.7 tutorial on input and output.
Use f-string alignment in formatted output
When inserting a value into a larger output line, specify its alignment and minimum width inside the f-string format field:
Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Repair Windows errors before they cause bigger problems3Scan for outdated or missing drivers - takes under a minute#1 Best Overall
f"{text:<6}"left-aligns the text and pads on the right.f"{text:>6}"right-aligns it and pads on the left.f"{text:^7}"centers it.
For example, f"{label:<12} {value:>6}" places a left-aligned label beside a right-aligned value. str.format() uses the same alignment markers: "{:<12} {:>6}".format(label, value). When you provide an alignment marker but no fill character, the format mini-language uses spaces. The Python 3.14.8 format specification documents the alignment options and minimum field width.
Use a different fill character when needed
Spaces are the default, but you can provide another fill character. For example, text.center(10, "*") centers the text using asterisks, and f"{text:*^10}" does the same with f-string formatting. In the format specification, the fill character goes immediately before the alignment marker.
Rank #2
Understand width and truncation
Width sets a minimum total length. If the string is already as long as or longer than the requested width, padding does not shorten it: "elephant".ljust(4) returns 'elephant'. The formatting width works the same way. If you need to truncate, do so explicitly—for example, text.ljust(width)[:width]—and consider whether removing the end of the string is acceptable.
These examples describe ordinary string-field formatting. They do not guarantee that every string will occupy the expected number of visual columns in every terminal; tabs and some Unicode characters can affect displayed alignment.
Quick Recap
Best Value
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




