Prints - padding strings
Continuing on the concept of printing, in this lesson we will cover how to pad a string to the left or right of it to a specified width.
Say we have an alphanumeric code that we want to store at a fixed
width, such as a unique identifier that starts at 00000001
and within one of the eight available spaces can be any alphanumeric
character. We can use
zfill
or rjust
to fill it infront/left of the
string, or use ljust
to fill it behind/right of the string.
zfill
only allows us to left pad a string with zeros.
rjust
and ljust
allow us to pad with any
character we want.
Ok, that's it for this lesson, a short and sweet one! Next are printing multi-line strings.