Home > Article > Backend Development > What does ljust mean in python?
Python ljust() method returns a new string with the original string left-aligned and padded with spaces to the specified length. If the specified length is less than the length of the original string, the original string is returned.
ljust() method syntax:
str.ljust(width[, fillchar])
Parameters
width -- Specify the string length.
fillchar -- fill character, default is space.
Return value
Returns a new string whose original string is left-aligned and padded with spaces to the specified length. If the specified length is less than the length of the original string, the original string is returned.
The following examples show how to use ljust():
#!/usr/bin/python str = "this is string example....wow!!!"; print str.ljust(50, '0');
The output results of the above examples are as follows:
this is string example....wow!!!000000000000000000
Related recommendations: " Python Tutorial》
The above is the detailed content of What does ljust mean in python?. For more information, please follow other related articles on the PHP Chinese website!