Skip to content

Instantly share code, notes, and snippets.

@pokk
Last active April 5, 2017 02:15
Show Gist options
  • Save pokk/614cdc616229f59cf470a597e957088a to your computer and use it in GitHub Desktop.
Save pokk/614cdc616229f59cf470a597e957088a to your computer and use it in GitHub Desktop.
In python align the string

Introduction

If you don't feel '\t' is convenient, you could customize the free space how many you want.

Talk is cheap. Show me the code.

# Align right
s = 'test'.rjust(10)
# >>> "test      "


# Align left
s = 'test'.ljust(10)
# >>> "      test"


# Center
s = 'test'.center(10)
# >>> "   test   "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment