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 ...
随机推荐
- VBS 数组冒泡排序
'定义变量 Dim arr1 '数组赋值 arr1 = array(, , , , , , ,) To UBound(arr1) To UBound(arr1) k=arr1(m) If arr1(m ...
- CF553E Kyoya and Train
Kyoya and Train 一个有\(n\)个节点\(m\)条边的有向图,每条边连接了\(a_i\)和\(b_i\),花费为\(c_i\). 每次经过某一条边就要花费该边的\(c_i\). 第\( ...
- 结构型模式(七) 代理模式(Proxy)
一.动机(Motivate) 在面向对象系统中,有些对象由于某种原因(比如对象创建的开销很大,或者某些操作需要安全控制,或者需要进程外的访问等),直接访问会给使用者.或者系统结构带来很多麻烦.如何在不 ...
- jpg/jpeg/png格式的区别与应用场景
注:在存储图像时采用JPG还是PNG主要依据图像上的色彩层次和颜色数量进行选择 一..jpg/jpeg格式的图片(jpg全名:jpeg) JPG(或是JPEG): 优点: (1)占用内存小,网页加载速 ...
- C++编译原理
链接
- node gyp编译所需要的环境
安装ms的build工具包,自带python npm install --global --production windows-build-tools
- FasfDFS整合Java实现文件上传下载功能实例详解
https://www.jb51.net/article/120675.htm 在上篇文章给大家介绍了FastDFS安装和配置整合Nginx-1.13.3的方法,大家可以点击查看下. 今天使用Java ...
- (尚001)Vue框架介绍
框架出现时间: Angular -->React(组件化+虚拟动) -->Vue(读作view) 1.Vue.js是什么?(作者:尤雨溪(一位华裔前Google工程师)) 尤 ...
- C函数指针数组的定义和使用
1.使用函数指针数组来实现计算器 2.通过函数指针变量来调用对应的函数 #include <stdio.h> int add(int a,int b){ return a+b; } int ...
- leetcode解题报告(28):Remove Linked List Elements
描述 Remove all elements from a linked list of integers that have value val. Example Given: 1 --> 2 ...