You are viewing a single comment's thread. Return to all comments →
Bro...how the n value in rjust() is decreasing...first it will print n spaces than in next iteration what will happen..please explain
rjust does not add n spaces to the string, it makes the string n spaces long in total
Consider the example "john".rjust(5)
This doesnt actually give 5 spaces to the string.
Consider the given string as a block [j][o][h][n](i.e there are four blocks)
As we have given width=5 and the given string is of 4 blocks ,it just adds one more block(i.e,the empty block which is a space) to make it equal to 5. [j][o][h][n]
So now it becomes " john".Make note of the space before the string.
If you specify any char,the space then gets filled with the given char.