关于字符串

来源:互联网 发布:十字绣diy软件 编辑:程序博客网 时间:2024/06/05 13:44

1. ljust()函数的使用:左对齐

Description:
The method ljust() returns the string left justified(左对齐) in a string of length width. Padding is done using the specified fillchar (default is a space). The original string is returned if width is less than len(s).

Syntax:
Following is the syntax for ljust() method :

str.ljust(width[, fillchar])

Parameters:
- width – This is string length in total after padding.
- fillchar – This is filler character, default is a space.

使用场景
看个例子就明白了:

>>> print "Brown:".ljust(15), 97Brown:          97>>> print "Richard Lee:".ljust(15), 90Richard Lee:    90

是不是对齐看起来非常美观。

0 0
原创粉丝点击