Python Basic - ljust( ) 、center( )、rjust( )

先定义几个字符串变量

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.

查看全部内置字符串处理方法,请点击

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值