•        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 左、右对齐 居中的更多相关文章

  1. python ljust,rjust,center,zfill对齐使用方法

    字符串在输出时的对齐:S.ljust(width,[fillchar]) #输出width个字符,S左对齐,不足部分用fillchar填充,默认的为空格. S.rjust(width,[fillcha ...

  2. Python: ljust()|rjust()|center()字符串对齐

    通过某种对齐方式来格式化字符串 ①对于基本的操作,可以使用字符串的ljust(),rjust(),center() ②函数format()同样可以用来很容易的对齐字符串,使用<,>,~

  3. Python3基础 str translate 将指定字符转换成另一种特定字符

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  4. Python3基础 str 循环输出list中每个单词及其长度

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  5. Python3基础 str format 位置参数与关键字参数

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  6. Python3基础 str 通过拆分字符串与插入新的内容形成新的字符串

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  7. Python3基础 str while+iter+next 字符串的遍历

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  8. Python3基础 str split 用指定的字符将字符串分割

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  9. Python3基础 str swapcase 英文字母大小写反转

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

随机推荐

  1. pyserial 挺强大的

    Ref: https://pythonhosted.org/pyserial/ pyserial写的很规范,无论安装和使用都非常的容易,目前使用下来非常好. 没有使用它做过压力测试,不知道表现如何. ...

  2. 0029redis单机版环境搭建

    linux环境下安装单机版redis,主要分为如下几步: 1. 安装gcc 2.下载安装包 3.解压安装包 4.进入解压目录并执行make和make install命令 5.查看默认安装目录 6.更改 ...

  3. 用python实现多线程爬取影视网站全部视频方法【笔记】

    我拿这个站点作为案例:https://91mjw.com/  其他站点方法都是差不多的. 第一步:获得整站所有的视频连接 html = requests.get("https://91mjw ...

  4. machine learning (2)-linear regression with one variable

    machine learning- linear regression with one variable(2) Linear regression with one variable = univa ...

  5. spring依赖注入实例

    依赖注入: BL public class T01BL implements Serializable { private static final Log logger = LogFactory.g ...

  6. sql注入和防sql注入

    sql注入: from pymysql import * def main(): # 创建连接 conn = connect(host="127.0.0.1", port=3306 ...

  7. 3D-2D透视投影数学推导

    请尊重作者,禁止私自盗用图片!

  8. Django REST framework认证权限和限制 源码分析

    1.首先 我们进入这个initial()里面看下他内部是怎么实现的. 2.我们进入里面看到他实现了3个方法,一个认证,权限频率 3.我们首先看下认证组件发生了什么 权限: 啥都没返回,self.per ...

  9. Tensorflow细节-P160-迁移学习

    这是一个完整的程序,值得保存 1.对图片进行预处理并保存 import glob import os.path import numpy as np import tensorflow as tf f ...

  10. GBDT 算法

    GBDT (Gradient Boosting Decision Tree) 梯度提升迭代决策树.GBDT 也是 Boosting 算法的一种,但是和 AdaBoost 算法不同(AdaBoost 算 ...