•        Python : 3.7.3
  •          OS : Ubuntu 18.04.2 LTS
  •         IDE : pycharm-community-2019.1.3
  •       Conda : 4.7.5
  •    typesetting : Markdown

code

  1. coder@ubuntu:~$ conda activate py37
  2. (py37) coder@ubuntu:~$ ipython
  3. Python 3.7.3 (default, Mar 27 2019, 22:11:17)
  4. Type 'copyright', 'credits' or 'license' for more information
  5. IPython 7.5.0 -- An enhanced Interactive Python. Type '?' for help.
  6. In [1]: content = "123"
  7. In [2]: # 原字符串左对齐,并用 - 填充直到字符串长度为6
  8. In [3]: content.ljust(6, '-')
  9. Out[3]: '123---'
  10. In [4]: # 原字符串右对齐,并用 - 填充直到字符串长度为6
  11. In [5]: content.rjust(6, '-')
  12. Out[5]: '---123'
  13. In [6]: # 原字符串居中,并用 - 填充直到字符串长度为6
  14. In [7]: content.center(6, '-')
  15. Out[7]: '-123--'
  16. In [8]: # 原字符串居中,并用 - 填充直到字符串长度为7
  17. In [9]: content.center(7, '-')
  18. Out[9]: '--123--'
  19. In [10]: exit
  20. (py37) coder@ubuntu:~$ conda deactivate
  21. coder@ubuntu:~$

source_code

  1. def ljust(self, *args, **kwargs): # real signature unknown
  2. """
  3. Return a left-justified string of length width.
  4. Padding is done using the specified fill character (default is a space).
  5. """
  6. pass
  7. def rjust(self, *args, **kwargs): # real signature unknown
  8. """
  9. Return a right-justified string of length width.
  10. Padding is done using the specified fill character (default is a space).
  11. """
  12. pass
  13. def center(self, *args, **kwargs): # real signature unknown
  14. """
  15. Return a centered string of length width.
  16. Padding is done using the specified fill character (default is a space).
  17. """
  18. 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. (一)WCF基础

    我们近期在做项目的时候用到了WCF,之前已经看了部分视频,对于WCF有了一定的了解,但仅限于能够根据搭建好的框架使用WCF,还不了解.所以就进行了研究,这样既有实践也能增加理论,二者结合,使用起来更胜 ...

  2. flask处理数据,页面实时刷新展示

    背景: 后端 flask(python)处理数据,页面实时刷新,类似于打包页面的动态展示,展示效果如图: 代码如下: 前端主要使用以下循环处理, 2--- 2秒刷新一次 {% if 0 == stop ...

  3. phpcms站点部署

    1 wamp部署使用wamp2.4以下版本. 2.4版本自带的php5.4以上底层变化,phpcms运行不了. 2.2版自带的php5.3.10可以兼容. 2 安装配置时,尽量为每个站点配置(http ...

  4. 十一.Protobuf3可选项

    Protobuf3 可选项 .proto文件中可以声明许多选项.选项不会改变声明的整体含义,但可能会影响在特定上下文中处理声明的方式.可用选项的完整列表在google/protobuf/descrip ...

  5. 详解C++中基类与派生类的转换以及虚基类

    很详细!转载链接 C++基类与派生类的转换在公用继承.私有继承和保护继承中,只有公用继承能较好地保留基类的特征,它保留了除构造函数和析构函数以外的基类所有成员,基类的公用或保护成员的访问权限在派生类中 ...

  6. python字符串、字符串处理函数及字符串相关操作

    python字符串.字符串处理函数及字符串相关操作 字符串介绍 python字符串表示 Python除处理数字外还可以处理字符串,字符串用单撇号或双撇号包裹: >>> 'spam e ...

  7. YAML_10 把监听端口是8080的Apache服务全部停止

    ansible]# vim ad.yml --- - hosts: cache   remote_user: root   tasks:     - shell: netstat -atunlp  | ...

  8. Optimize Cube.js Performance with Pre-Aggregations

    转自:https://cube.dev/blog/high-performance-data-analytics-with-cubejs-pre-aggregations/ 可以了解 Pre-Aggr ...

  9. 32、reduceByKey和groupByKey对比

    一.groupByKey 1.图解 val counts = pairs.groupByKey().map(wordCounts => (wordCounts._1, wordCounts._2 ...

  10. LayuiAdmin 单页版关闭当前页面tab的方式-图文

    需要关闭的时候 调用 parent.layui.admin.events.closeThisTabs() 即可执行当前页面的关闭 $.post("/index.php/WebAdmin/Wx ...