python实现指定字符串补全空格的方法
作者:重负在身 时间:2023-06-22 21:57:40
本文实例讲述了python实现指定字符串补全空格的方法。分享给大家供大家参考。具体分析如下:
如果希望字符串的长度固定,给定的字符串又不够长度,我们可以通过rjust,ljust和center三个方法来给字符串补全空格
rjust,向右对其,在左边补空格
s = "123".rjust(5)
assert s == " 123"
ljust,向左对其,在右边补空格
s = "123".ljust(5)
assert s == "123 "
center,让字符串居中,在左右补空格
s = "123".center(5)
assert s == " 123 "
希望本文所述对大家的Python程序设计有所帮助。
标签:python,字符串
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Linux系统(X64)安装Oracle11g完整安装图文教程另附基本操作
2023-07-07 08:25:36
![](https://img.aspxhome.com/file/2023/0/63360_0s.jpg)
关于useSSL=false和true的区别及说明
2024-01-25 03:27:40
PHP 实现一种多文件上传的方法
2024-05-03 15:07:11
SQL Server 2000中生成XML的小技巧
2009-02-13 17:12:00
python实现指定文件夹下的指定文件移动到指定位置
2023-07-03 08:21:11
如何在sae中设置django,让sae的工作环境跟本地python环境一致
2022-03-09 22:04:54
Python实现高斯函数的三维显示方法
2023-07-04 01:47:22
![](https://img.aspxhome.com/file/2023/9/59639_0s.jpg)
li隔行换色改进版
2024-04-29 13:40:23
Python进阶之全面解读高级特性之切片
2023-08-06 21:28:00
Oracle REGEXP_LIKE模糊查询用法例子
2023-07-19 08:26:22
![](https://img.aspxhome.com/file/2023/8/64448_0s.png)
python 中的 BeautifulSoup 网页使用方法解析
2022-06-25 19:09:26
Python3+Appium安装使用教程
2023-08-22 13:38:32
![](https://img.aspxhome.com/file/2023/6/77906_0s.png)
Python中方法的缺省参数问题解读
2022-10-07 17:00:45
![](https://img.aspxhome.com/file/2023/9/92059_0s.png)
GoLang并发编程中条件变量sync.Cond的使用
2024-04-25 15:28:40
python sklearn常用分类算法模型的调用
2021-06-18 11:42:25
python多线程编程方式分析示例详解
2023-05-13 04:56:01
Jinja2实现模板渲染与访问对象属性流程详解
2022-09-18 14:44:20
![](https://img.aspxhome.com/file/2023/2/65482_0s.png)
树莓派用python中的OpenCV输出USB摄像头画面
2023-11-04 12:12:49
![](https://img.aspxhome.com/file/2023/1/85271_0s.jpg)
sql2005 HashBytes 加密函数
2024-01-21 11:28:23
python清除字符串里非数字字符的方法
2023-08-12 02:47:32