Chapter 18: Center method

If we want to add extra characters to both sides of a string (left and right), we can use the center method. Refer to the code below for a clearer understanding.

# we want to make it like  ****Free Learning****
name = "Free Learning"
print(name.center(19, "#")) #Here, 19 is 13 + 6. where 13 is length of string and 6 is for stars (3 each side).
Output: ###Free Learning###
#suppose we don't know the length of string, then, we use center method with len function.
name1 = input("Enter your name: ")
print(name1.center(len(name1)+6, "@")) #here, len function found the lenth of string and 6 @ symbol print.
Output: Enter your name: Free Learning
@@@Free Learning@@@