目的实现字符串的左对齐,右对齐,居中对齐。
方法字符串内置了以下方法:其中width是指包含字符串S在内的宽度,fillchar默认是空格,也可以指定填充字符Python 3.14.3微软官方的 Python 扩展,是 VS Code 安装量最高的扩展(209M+)。集成 IntelliSense(通过 Pylance)、调试(通过 Python Debugger)、代码检查、格式化、重构和单元测试等功能。支持 Jupyter Notebook、虚拟环境管理和多 Python 版本切换。
下载复制代码代码如下:string.ljust(s, width[, fillchar]) string.rjust(s, width[, fillchar]) string.center(s, width[, fillchar])复制代码代码如下:In [6]: a='Hello!'In [7]: print a.ljust(10,'+') Hello!++++In [8]: print a.rjust(10,'+')++++Hello!In [9]: print a.center(10,'+')++Hello!++
