Introduction to the ljust () method for processing strings in Python, pythonljust
The ljust () method returns the left-aligned string length and width. Fill is done by using the specified fillchar (space by default ). If the width is less than len (s), the original string is returned.
Syntax
The following is the syntax of the ljust () method:
Str. ljust (width [, fillchar])
Parameters
- Width -- this is the total length of the filled string.
- Fillchar -- this is a fill character. The default value is space.
Return Value
This method returns the length and width of the left-aligned string. Fill is done by using the specified fillchar (space by default ). If the width is smaller than len (s), the original string is returned.
Example
The following example shows how to use the ljust () method.
#! /Usr/bin/pythonstr = "this is string example... wow !!! "; Print str. ljust (50, '0 ');
When we run the above program, it will produce the following results:
This is string example... wow !!! 000000000000000000