String left just and right just will return left and right justified string as per width and fill character.

Syntax of Str.ljust & Str.rjust:

ljust(width,fill char)

rjust(width,fill char)

width will be an integer value & By default fill character is space and we can mention any other character of length one.it can not be more than one length otherwise it will raise an error.

how to write str.ljust and str.rjust in python
String ljust &rjust

As shown image above ljust returned string of len 13 and filled with g in right side of string. and right just will return string of length 13 padded with space on left side.

By SC

One thought on “Str.ljust &rjust in python”

Leave a Reply

Your email address will not be published. Required fields are marked *