Title: Add Padding Around String
Slug: add_padding_around_string
Summary: Add Padding Around String Using Python.
Date: 2017-02-02 12:00
Category: Python
Tags: Basics
Authors: Chris Albon

Create Some Text


In [46]:
text = 'Chapter 1'

Add Padding Around Text


In [47]:
# Add Spaces Of Padding To The Left
format(text, '>20')


Out[47]:
'           Chapter 1'

In [48]:
# Add Spaces Of Padding To The Right
format(text, '<20')


Out[48]:
'Chapter 1           '

In [49]:
# Add Spaces Of Padding On Each Side
format(text, '^20')


Out[49]:
'     Chapter 1      '

In [50]:
# Add * Of Padding On Each Side
format(text, '*^20')


Out[50]:
'*****Chapter 1******'