Ways To Align Text Strings In Python

In this article, I’ll show you various ways to align strings in Python. There are many different ways we can align strings in Python. Let’s have a look at those:

Left Align

For left-aligned text, you can use ljust(…) function, which stands for left justification.

my_text = “Shift me.”

print(my_text.ljust(25) )

The above lines will display left-aligned text with a length of 25.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store