这篇教程Python3 center()方法写得很实用,希望能帮到您。 center() 方法返回一个指定的宽度 width 居中的字符串,fillchar 为填充的字符,默认为空格。 语法center()方法语法: str.center(width[, fillchar]) 参数- width -- 字符串的总宽度。
- fillchar -- 填充字符。
返回值返回一个指定的宽度 width 居中的字符串,如果 width 小于字符串宽度直接返回字符串,否则使用 fillchar 去填充。 实例以下实例展示了center()方法的实例: #!/usr/bin/python3str = "[www.codercto.com]"print ("str.center(40, '*') : ", str.center(40, '*')) 以上实例输出结果如下: str.center(40, '*') : ************[www.codercto.com]************ Python3 capitalize()方法 Python3 count()方法 |