Skip to main content
Fixed a very old typo
Source Link
johnsyweb
  • 142.9k
  • 26
  • 197
  • 253

Use str.ljust():

>>> 'Hi'.ljust(6) 'Hi ' 

You should also consider string.zfill(), str.ljust()str.rjust() and str.center() for string formatting. These can be chained and have the 'fill' character specified, thus:

>>> ('3'.zfill(8) + 'blind'.rjust(8) + 'mice'.ljust(8, '.')).center(40) ' 00000003 blindmice.... ' 

These string formatting operations have the advantage of working in Python v2 and v3.

Take a look at pydoc str sometime: there's a wealth of good stuff in there.

Use str.ljust():

>>> 'Hi'.ljust(6) 'Hi ' 

You should also consider string.zfill(), str.ljust() and str.center() for string formatting. These can be chained and have the 'fill' character specified, thus:

>>> ('3'.zfill(8) + 'blind'.rjust(8) + 'mice'.ljust(8, '.')).center(40) ' 00000003 blindmice.... ' 

These string formatting operations have the advantage of working in Python v2 and v3.

Take a look at pydoc str sometime: there's a wealth of good stuff in there.

Use str.ljust():

>>> 'Hi'.ljust(6) 'Hi ' 

You should also consider string.zfill(), str.rjust() and str.center() for string formatting. These can be chained and have the 'fill' character specified, thus:

>>> ('3'.zfill(8) + 'blind'.rjust(8) + 'mice'.ljust(8, '.')).center(40) ' 00000003 blindmice.... ' 

These string formatting operations have the advantage of working in Python v2 and v3.

Take a look at pydoc str sometime: there's a wealth of good stuff in there.

English (Simplified)
Source Link
johnsyweb
  • 142.9k
  • 26
  • 197
  • 253

Use str.ljust():

>>> 'Hi'.ljust(6) 'Hi ' 

You should also consider string.zfill(), str.ljust() and str.centrecenter() for string formatting. These can be chained and have the 'fill' character specified, thus:

>>> ('3'.zfill(8) + 'blind'.rjust(8) + 'mice'.ljust(8, '.')).center(40) ' 00000003 blindmice.... ' 

These string formatting operations have the advantage of working in Python v2 and v3.

Take a look at pydoc str sometime: there's a wealth of good stuff in there.

Use str.ljust():

>>> 'Hi'.ljust(6) 'Hi ' 

You should also consider string.zfill(), str.ljust() and str.centre() for string formatting. These can be chained and have the 'fill' character specified, thus:

>>> ('3'.zfill(8) + 'blind'.rjust(8) + 'mice'.ljust(8, '.')).center(40) ' 00000003 blindmice.... ' 

These string formatting operations have the advantage of working in Python v2 and v3.

Take a look at pydoc str sometime: there's a wealth of good stuff in there.

Use str.ljust():

>>> 'Hi'.ljust(6) 'Hi ' 

You should also consider string.zfill(), str.ljust() and str.center() for string formatting. These can be chained and have the 'fill' character specified, thus:

>>> ('3'.zfill(8) + 'blind'.rjust(8) + 'mice'.ljust(8, '.')).center(40) ' 00000003 blindmice.... ' 

These string formatting operations have the advantage of working in Python v2 and v3.

Take a look at pydoc str sometime: there's a wealth of good stuff in there.

Formatting. Added link to Pydoc documentation.
Source Link
johnsyweb
  • 142.9k
  • 26
  • 197
  • 253

Use str.ljust()str.ljust():

>>> 'Hi'.ljust(6) 'Hi ' 

You should also consider string.zfill()string.zfill(), str.ljust()str.ljust() and str.centre()str.centre() for string formatting. These can be chained and have the 'fill''fill' character specified, thus:

>>> ('3'.zfill(8) + 'blind'.rjust(8) + 'mice'.ljust(8, '.')).center(40) ' 00000003 blindmice.... ' 

These string formatting operations have the advantage of working in Python v2 and v3.

Take a look at pydoc strpydoc str sometime: there's a wealth of good stuff in there.

Use str.ljust():

>>> 'Hi'.ljust(6) 'Hi ' 

You should also consider string.zfill(), str.ljust() and str.centre() for string formatting. These can be chained and have the 'fill' character specified, thus:

>>> ('3'.zfill(8) + 'blind'.rjust(8) + 'mice'.ljust(8, '.')).center(40) ' 00000003 blindmice.... ' 

These string formatting operations have the advantage of working in Python v2 and v3.

Take a look at pydoc str sometime: there's a wealth of good stuff in there.

Use str.ljust():

>>> 'Hi'.ljust(6) 'Hi ' 

You should also consider string.zfill(), str.ljust() and str.centre() for string formatting. These can be chained and have the 'fill' character specified, thus:

>>> ('3'.zfill(8) + 'blind'.rjust(8) + 'mice'.ljust(8, '.')).center(40) ' 00000003 blindmice.... ' 

These string formatting operations have the advantage of working in Python v2 and v3.

Take a look at pydoc str sometime: there's a wealth of good stuff in there.

Added similar operations and note about compatibility.; deleted 2 characters in body
Source Link
johnsyweb
  • 142.9k
  • 26
  • 197
  • 253
Loading
Source Link
johnsyweb
  • 142.9k
  • 26
  • 197
  • 253
Loading