文章目录
先定义几个字符串变量
string1 = "Hello,World."
string2 = "Python is the best computer language"
string3 = "Python is the language that the most easy of the\tworld."
string4 = "3 is bigger than 1"
string5 = "Python is the {what} that the most {how} of the world."
ljust( )–总长度100,string3的字符靠左排,不够100的用*补齐
print(string3.ljust(100,"*")) # 总长度100,string3的字符靠左排,不够100的用*补齐
测试输出
Python Is the Language That the most easy of the world.*********************************************
center( )–将string3所存储的内容嵌入到行中,并且居中,字符串必需小于总长度,字符串长度不够的将使用#补齐
print(string3.center(100,"#")) #150为固定的输出长度,将string3所存储的内容嵌入到行中,并且居中,字符串必需小于总长度,字符串长度不够的将使用#补齐。
测试输出
######################Python Is the Language That the most easy of the world.#######################
rjust( )–靠右排,不够100的用*补齐
print(string3.rjust(100,"*")) # 总长度100,string3的字符靠右排,不够100的用*补齐
测试输出
*********************************************Python Is the Language That the most easy of the world.