Python string str.rjust() method

Reprinted from: https://www.yiibai.com/python/string_rjust.html

Example

The following example shows the usage of the rjust() method

Example 1:

str = "this is string example....wow!!!"
print (str.rjust(50, '*'))

When running the above program, it produces the following result

******************this is string example....wow!!!

Example 2:

str.rjust(width, fillchar)
print("aa".rjust(8))

result

      aa

effect

Use the specified fillchar (or a space if not filled) to fill the right-aligned string whose length is width, and return it.
If the width is less than str.len , the original string is returned.

Example 3:

print("作业ID".rjust(8))
print("1".rjust(8))
    作业ID
           1

The Chinese character is also regarded as a character placeholder, and the English character is regarded as a character, so it is easy to be inaccurate.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325728043&siteId=291194637