Python3基础 str ljust-rjust-center 左、右对齐 居中
- Python : 3.7.3
- OS : Ubuntu 18.04.2 LTS
- IDE : pycharm-community-2019.1.3
- Conda : 4.7.5
- typesetting : Markdown
code
coder@ubuntu:~$ conda activate py37
(py37) coder@ubuntu:~$ ipython
Python 3.7.3 (default, Mar 27 2019, 22:11:17)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.5.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: content = "123"
In [2]: # 原字符串左对齐,并用 - 填充直到字符串长度为6
In [3]: content.ljust(6, '-')
Out[3]: '123---'
In [4]: # 原字符串右对齐,并用 - 填充直到字符串长度为6
In [5]: content.rjust(6, '-')
Out[5]: '---123'
In [6]: # 原字符串居中,并用 - 填充直到字符串长度为6
In [7]: content.center(6, '-')
Out[7]: '-123--'
In [8]: # 原字符串居中,并用 - 填充直到字符串长度为7
In [9]: content.center(7, '-')
Out[9]: '--123--'
In [10]: exit
(py37) coder@ubuntu:~$ conda deactivate
coder@ubuntu:~$
source_code
def ljust(self, *args, **kwargs): # real signature unknown
"""
Return a left-justified string of length width.
Padding is done using the specified fill character (default is a space).
"""
pass
def rjust(self, *args, **kwargs): # real signature unknown
"""
Return a right-justified string of length width.
Padding is done using the specified fill character (default is a space).
"""
pass
def center(self, *args, **kwargs): # real signature unknown
"""
Return a centered string of length width.
Padding is done using the specified fill character (default is a space).
"""
pass
resource
- [文档 - English] docs.python.org/3
- [文档 - 中文] docs.python.org/zh-cn/3
- [规范] www.python.org/dev/peps/pep-0008
- [规范] zh-google-styleguide.readthedocs.io/en/latest/google-python-styleguide/python_language_rules
- [源码] www.python.org/downloads/source
- [ PEP ] www.python.org/dev/peps
- [平台] www.cnblogs.com
- [平台] gitee.com
Python具有开源、跨平台、解释型、交互式等特性,值得学习。
Python的设计哲学:优雅,明确,简单。提倡用一种方法,最好是只有一种方法来做一件事。
代码的书写要遵守规范,这样有助于沟通和理解。
每种语言都有独特的思想,初学者需要转变思维、踏实践行、坚持积累。
Python3基础 str ljust-rjust-center 左、右对齐 居中的更多相关文章
- python ljust,rjust,center,zfill对齐使用方法
字符串在输出时的对齐:S.ljust(width,[fillchar]) #输出width个字符,S左对齐,不足部分用fillchar填充,默认的为空格. S.rjust(width,[fillcha ...
- Python: ljust()|rjust()|center()字符串对齐
通过某种对齐方式来格式化字符串 ①对于基本的操作,可以使用字符串的ljust(),rjust(),center() ②函数format()同样可以用来很容易的对齐字符串,使用<,>,~
- Python3基础 str translate 将指定字符转换成另一种特定字符
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- Python3基础 str 循环输出list中每个单词及其长度
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- Python3基础 str format 位置参数与关键字参数
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- Python3基础 str 通过拆分字符串与插入新的内容形成新的字符串
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- Python3基础 str while+iter+next 字符串的遍历
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- Python3基础 str split 用指定的字符将字符串分割
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- Python3基础 str swapcase 英文字母大小写反转
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
随机推荐
- test20190829 神大校赛模拟
100+100+0=200,聪明搬题人题面又出锅了. 最短路径(path) 给定有向图,包含 n 个节点和 m 条有向边. 一条A 到 B 的路径是最短路径当且仅当不存在另一条从A 到 B 的路径比它 ...
- 「AHOI / HNOI2017」礼物
「AHOI / HNOI2017」礼物 题目描述 我的室友最近喜欢上了一个可爱的小女生.马上就要到她的生日了,他决定买一对情侣手环,一个留给自己,一个送给她.每个手环上各有 n 个装饰物,并且每个装饰 ...
- *.net框架 - IEnumerable类 & IQueryable类
什么使用IQueryable<T> 查询返回类型为什么用IQueryable<T>,而不用 IEnumerable<T>类型? IQueryable接口实现IEnu ...
- 接口-DBLINK初尝试
需求: 将寿险核心库中的黑名单数据提取到团险核心中,供团险核心使用,并且在核心前端页面需配置对应的菜单,提供相应的按钮,该接口采用dblink的方式进行提取. 通过本地数据库配置dblink访问远程数 ...
- js中检测类型问题
<script> // var str = '少壮不努力,老大徒伤悲'; // console.log(str instanceof String); // consol ...
- am335x using brctl iptables dhcpcd make multi wan & multi lan network(十五)
构建多LAN口多WAN口动态网络 [目的] 在AM335X定制动态网络功能,如下所示,在系统当中有两个以太网口,有4G模块,有wifi芯片8188eu支持AP+STA功能. [实验环境] 1. Ub ...
- Optimize Cube.js Performance with Pre-Aggregations
转自:https://cube.dev/blog/high-performance-data-analytics-with-cubejs-pre-aggregations/ 可以了解 Pre-Aggr ...
- AtCoder Grand Contest 004题解
传送门 \(A\) 咕咕 int a,b,c; int main(){ scanf("%d%d%d",&a,&b,&c); if((a&1^1)|( ...
- word 新建一行文字不能左对齐
- Ruby on Rails框架(1)-安装全攻略
序 关于Rails的三句箴言 (1)DRY:Don't Repeat Yourself(不要重复你自己) rails的开发理念,不要用你的代码不停的重复,rails框架给开发者提供了一套非常完善的支持 ...