You can look into str.ljust
and str.rjust
I believe.
The alternative is probably to use the format method:
>>> '{:<30}'.format('left aligned')
'left aligned '
>>> '{:>30}'.format('right aligned')
' right aligned'
>>> '{:^30}'.format('centered')
' centered '
>>> '{:*^30}'.format('centered') # use '*' as a fill char
'***********centered***********'
Related Contents:
- Split Strings into words with multiple word boundary delimiters
- How to convert strings into integers?
- Fast punctuation removal with pandas
- What exactly does the .join() method do?
- Remove unwanted parts from strings in a column
- Calculate cosine similarity given 2 sentence strings
- Good Python modules for fuzzy string comparison? [closed]
- How to split a string of space separated numbers into integers?
- using backslash in python (not to escape)
- Convert regular Python string to raw string
- How to check a string for specific characters?
- Pandas column access w/column names containing spaces
- Proper indentation for multiline strings?
- How do I split the definition of a long string over multiple lines?
- Suppress the u’prefix indicating unicode’ in python strings
- Easy way of finding decimal places
- Product code looks like abcd2343, how to split by letters and numbers?
- How to “properly” print a list?
- Extract email sub-strings from large document
- Understanding string reversal via slicing
- subprocess “TypeError: a bytes-like object is required, not ‘str'”
- When splitting an empty string in Python, why does split() return an empty list while split(‘\n’) returns [”]?
- Check if string has date, any format
- Extract a string between double quotes
- How do I convert a list into a string with spaces in Python?
- Safely evaluate simple string equation
- Why is True returned when checking if an empty string is in another?
- How do I check for an EXACT word in a string in python
- Removing control characters from a string in python
- Replace string within file contents [duplicate]
- Having both single and double quotation in a Python string
- Print without b’ prefix for bytes in Python 3
- Check presence of vowels in a string
- Add commas into number string [duplicate]
- How to remove all characters before a specific character in Python?
- How to count digits, letters, spaces for a string in Python?
- How do I escape curly-brace ({}) characters in a string while using .format (or an f-string)?
- How can I pad a string with spaces from the right and left? [duplicate]
- How do I check if raw input is integer in python 2.7?
- Are strings cached? [duplicate]
- Pandas read_csv dtype leading zeros
- Variable interpolation in Python [duplicate]
- How to decode a video (memory file / byte string) and step through it frame by frame in python?
- How do I create a multiline Python string with inline variables?
- How do you check in python whether a string contains only numbers?
- How can I copy a Python string?
- Unknown python expression filename=r’/path/to/file’
- How can I split a string of a mathematical expressions in python?
- Column of lists, convert list to string as a new column
- CSV reader behavior with None and empty string