Introduction to the ljust () method for processing strings in Python

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.