This article describes how to use the ljust () method to process strings in Python. it is a basic knowledge in Python learning. For more information, see ljust () 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