In Python, you can use the string format()
method to left align string. In the below code, <30
is used to left align a string. The default alignment is left alignment. Less than a sign (<)
is used to left align a string.
Step 1: Create a string
str = "CodeAllow" print("str = ", str) print("str type = ", type(str))
Step 2: Left align a string
print("str = ", "{:30}".format(str))
Output:
str = CodeAllow
str type = <class 'str'>
str = CodeAllow
Free resources to learn advanced skills: AiHints and CodeAllow