Linked Questions
62 questions linked to/from How can I fill out a Python string with spaces?
Score of 122
10 answers
237961 views
How to pad a string to a fixed length with spaces [duplicate]
I'm sure this is covered in plenty of places, but I don't know the exact name of the action I'm trying to do so I can't really look it up. I've been reading an official Python book for 30 minutes ...
Score of 72
2 answers
77468 views
How can I pad a string with spaces from the right and left? [duplicate]
I have two scenarios where I need to pad a string with whitespaces up to a certain length, in both the left and right directions (in separate cases). For instance, I have the string:
TEST
but I need ...
Score of 2
1 answer
7180 views
Print spacing in Python [duplicate]
Is it possible to print multiple strings on one line in such a way that the final string will always be x amount of space from the left? For example, is there anyway to print a result similar to this, ...
Score of -1
1 answer
1242 views
How can I print a pyramid shape using a nested loop? [duplicate]
I want to produce a similar shape to the above using a nested loop. Can anyone here help me with that?
print(' #')
print(' ###')
print(' ####')
print(' #####')
print(' #######'...
Score of 1
1 answer
1862 views
Python 3.6 - Using formatting in a print statement to neatly align output columns [duplicate]
Sorry if this question has been asked before, (Yes, I've checked) but I am writing a program for Python 3.6 and having difficulty trying to align the output of columns like so:
0, 0, 0, // - ...
Score of -3
5 answers
283 views
How to padding spaces in the end to make the string is fixed-lenght [duplicate]
I want to padding spaces of each input item if it is less than 5 characters,
Then padding each to 5 characters long.
How to do it with Python
input = [477 , 4770, 47711]
output = ["477 ", "4770 "...
Score of 0
3 answers
195 views
I want to change the amount of spaces before a word [duplicate]
I am trying to have a user input a word and a certain number of spaces before it:
e.g. if the user wants 10 spaces before a word it will print:
..........foo
But without the .'s (That's just to make ...
Score of -3
2 answers
270 views
python padding formatting alternative? [duplicate]
Is there a custom way of padding lines of text in python, I am using the escape characters "\t", but I wonder if there is an alternative.
for example
print('My Name is:')
print('Rambo')
print('Mambo')...
Score of 0
1 answer
210 views
How to format print outputs of a text file? [duplicate]
I have a text file called animal.txt.
1.1 Animal Name : Dog
Animal Type : Mammal
Fur : Yes
Scale : No
1.2 Animal Name : Snake
Animal Type : Reptile
Fur ...
Score of 0
1 answer
98 views
Add apostrophes to string to make it a certain length python [duplicate]
I am writing a file which gets information about stock items from a csv, the issue is that most of the stock item IDs are 4 digits long, but some of them are 2 or 3 digits, and the remaining digits ...
Score of 0
3 answers
111 views
How to make the same space between words in python [duplicate]
I have two arrays with words. One is the words before processing, the second is after.
before = ['screen', 'properly', 'salients', 'spoiled', 'respond']
after = ['screens', 'properly', 'salient', '...
Score of 0
1 answer
86 views
Adding padding for string types [duplicate]
I have written below code to display a leading zero when the string representation of date has less than two digits?
'{}-{}-{:02d}'.format('6th', 'Jun', '1933')
But it is failing with an error:
...
Score of 0
0 answers
52 views
Is there any way to line up data in columns in python? [duplicate]
I have a coding assignment to line up data in columns.
Current code:
print('i i**2 i**3 2**i',sep=' ')
for i in range(1,13):
print(i, i**2,i**3,2**i,sep=' ')
I have written this code.
Kindly ...
Score of 0
1 answer
53 views
Is there a way to replace long spaces in print()? [duplicate]
I am trying to run a loop and I want to use print() on 1 line only but here it needs long spacing so that the letters are not overwritten from the previous print result, and for that I really need ...
Score of 201
8 answers
466073 views
How to print a string at a fixed width?
I have the following code (printing the occurrence of all permutations in a string):
def splitter(str):
for i in range(1, len(str)):
start = str[0:i]
end = str[i:]
yield (...