Adjusting Text ljust rjust center zfill expandtabs

The fenctions for adjestlbg text are as handy and convenient as the parsing functions. You'll use them a lot, particularly for attractive report printing.

Theljust(s, width) function left-justifies a string to a given width. The rjust(s, width) function right-justifies it. T^he center (s , width) function centers a string to a given width. Here are examples of all three:

>>> rjust("String",20) ' String'

>>> ljust("String",20) 'String '

>>> center("String", 20) ' String '

zfill (snum, width) pads a numeric string with leading zeros.

>>> zfill ("0.1", 10) '00000000.1'

expandtabs (s, tabsize) converts tabs into spaces that equal the width of the tabsize argument.

Create a string with tebs denoted by \t.

Expand the tabs to five spaces.

Expand the tabs to ten spaces,

Expand the tabs tf twonlel spaces.

Was this article helpful?

0 0

Post a comment