Home > Backend Development > Python Tutorial > What does ljust mean in python?

What does ljust mean in python?

藏色散人
Release: 2019-06-22 11:51:48
Original
9277 people have browsed it

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])
Copy after login

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');
Copy after login

The output results of the above examples are as follows:

this is string example....wow!!!000000000000000000
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template