当前位置:  首页>> 技术小册>> Python合辑2-字符串常用方法

26、center()

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

  1. s = 'Python is awesome!'
  2. s = s.center(30, '-')
  3. print(s)
  4. # ------Python is awesome!------

该分类下的相关小册推荐: