Home  >  Article  >  Backend Development  >  What does ljust mean in python?

What does ljust mean in python?

藏色散人
藏色散人Original
2019-06-22 11:51:489150browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn