We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
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.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Staircase
You are viewing a single comment's thread. Return to all comments →
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.