用python实现在字符串前插入某些固定的字符

Help on method_descriptor:

rjust(...)
    S.rjust(width[, fillchar]) -> str
    
    Return S right-justified in a string of length width. Padding is
    done using the specified fill character (default is a space).
(END)
>>> import sys
>>> 
>>> 
>>> str1 = ''
/*组成一个在Hello World前插入50个空格的字符串*/
>>> str2 = str1.rjust(50) + 'Hello world'
>>> print(str2)
                                                  Hello world
>>> help(str.rjust)

>>> 
/*组成一个总的字符串长度为70,在str2字符串前插入字符c的字符串,插入其他字符同样方法*/
>>> str3 = str2.rjust(70, 'c')
>>> print(str3)
ccccccccc                                                  Hello world
>>>
发布了223 篇原创文章 · 获赞 160 · 访问量 20万+

猜你喜欢

转载自blog.csdn.net/u014100559/article/details/102909743