Join Regular Classroom : Visit ClassroomTech

Python String – center() method

This is a string method that aligns the given string to the center with the help of a character as the filling element (space by default) for a desired length of the returned string.

Syntax:

string.center(desired_length, “element_of_filling”)

Example:

s = “CodeWindow
x = s.center(16, “-“)
print(x)

Output:

CodeWindow

Explanation:

It centers the string “CodeWindow” with the help of element “-” and returns a string with a length of 16.

 

You Missed
Also Checkout