Introduction to the string Alignment Method in Python

Source: Internet
Author: User

Introduction to the string Alignment Method in Python

This article mainly introduces the string Alignment Method in Python. This article describes the built-in methods of Python strings, such as ljust, lifecycle ust, and center. For more information, see

Purpose

Align the left, right, and center of the string.

Method

The string has the following built-in Methods: width refers to the width of the string S, fillchar is a space by default, you can also specify the Filling Character

The Code is as follows:

String. ljust (s, width [, fillchar])

String. Must ust (s, width [, fillchar])

String. center (s, width [, fillchar])

The Code is as follows:

In [6]: a = 'Hello! '

In [7]: print a. ljust (10, '+ ')

Hello! ++

In [8]: print a. Must ust (10, '+ ')

+++ Hello!

In [9]: print a. center (10, '+ ')

+ + Hello! ++

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.