zoukankan      html  css  js  c++  java
  • (转)Python

    https://zhuanlan.zhihu.com/p/33923344-----------Python小知识:用format格式化输出字符串
    版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u012515223/article/details/20463231

    字符串对齐

    Python中, 字符串对齐, 使用ljust(), 左对齐;rjust(), 右对齐;center(), 中间对齐;

    也可以修改第三个参数, 修改填充数据, 默认使用空格;

    代码如下:

    1.  
      # -*- coding: utf-8 -*-
    2.  
       
    3.  
      #====================
    4.  
      #File: TextExercise.py
    5.  
      #Author: Wendy
    6.  
      #Date: 2014-03-04
    7.  
      #====================
    8.  
       
    9.  
      #eclipse pydev, python2.7
    10.  
       
    11.  
      print('|' + 'hej'.ljust(20) + '|' + 'hej'.rjust(20) + '|' + 'hej'.center(20) + '|')
    12.  
      print('hej'.center(20, '+')) #一共有20个字符, 中间使用hej, 其他用+填充


    输出:

      1.  
        |hej | hej| hej |
      2.  
        ++++++++hej+++++++++
  • 相关阅读:
    特殊权限
    linux文件文本查找
    vim
    11.8-下视频录视频
    10.04-VSCode-Linux编程环境搭建
    10.26-thunderbird配置
    6.20-安装Nvidia gt660ti 显卡驱动
    6.19-搭建github博客
    2.10-常用系统维护
    6.18-WizNote MD 指南
  • 原文地址:https://www.cnblogs.com/liujiacai/p/9685167.html
Copyright © 2011-2022 走看看