We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
The string method str.center(width, [fillchar]) is used to create a centered string.
width = width of string;
fillchar = character that will fill the string. Default is whitespace.
# Prints " HELLO ". Width = 9, fills string with spaces by default.print("HELLO".center(9))# Prints "--HELLO--". print("HELLO".center(9,"-"))# Prints ".....BYE.....". Width = 15, fills string with "."print("BYE".center(15,"."))
In this problem, we see that the doormat consists of a number of centered strings of width M, with "-" as filling character:
Designer Door Mat
You are viewing a single comment's thread. Return to all comments →
The string method str.center(width, [fillchar]) is used to create a centered string.
width = width of string;
fillchar = character that will fill the string. Default is whitespace.
In this problem, we see that the doormat consists of a number of centered strings of width M, with "-" as filling character:
This is why many solutions (including mine) use .center(M, "-").