How to Use String center() Method in PythonPython Basics

The center() method returns a new string that is padded with the specified fillchar.


# -*- coding: UTF-8 -*-

str = "aaa"
print (",'*'): ",,'*'))

str = "hello python"
print (",'*'): ",,'*'))

Output:,'*'):  ***aaa****,'*'):  ****hello python****

Syntax[, fillchar])


Name Description
width The total width of the string
fillchar Filled characters

Return Value

It returns a string padded with specified fillchar.

© 2024, all rights reserved. Privacy Policy | Contact Us