• 技术文章 >Python技术 >Python基础教程

    Python center()方法

    silencementsilencement2019-07-04 13:49:45原创1780

    描述

    Python center() 返回一个原字符串居中,并使用空格填充至长度 width 的新字符串。默认填充字符为空格。

    语法

    center()方法语法:

    string.center(width[, fillchar])

    参数

    width -- 字符串的总宽度。

    fillchar -- 填充字符。

    返回值

    该方法返回一个原字符串居中,并使用空格填充至长度 width 的新字符串。

    实例

    以下实例展示了center()方法的实例:

    #!/usr/bin/python
     
    string = "this is string example....wow!!!";
     
    print "string.center(40, 'a') : ", string.center(40, 'a')

    以上实例输出结果如下:

    string.center(40, 'a') :  aaaathis is


    专题推荐:center方法
    品易云
    上一篇:Python endswith()方法 下一篇:Python find()方法

    相关文章推荐

    • Python字符串拼接(包含字符串拼接数字)• Python endswith()方法

    全部评论我要评论

    © 2021 Python学习网 苏ICP备2021003149号-1

  • 取消发布评论
  • 

    Python学习网