center(): Adding chars to both side of the string.
Python
String
my_str="plus2net.com"
print(my_str.center(30))
Output is here ( there are blank spaces at both sides of the string. Total length of the output string is equal to 30)
plus2net.com
With filling_char
my_str="plus2net.com"
print(my_str.center(30,'*'))
Output
*********plus2net.com*********
Syntax
center(length,filling_char)
length: required , the length of the string after adding filling_char at both sides.
filling_char : (optional), default is blank space, used at both sides of the string.
« All String methods
← Subscribe to our YouTube Channel here
This article is written by plus2net.com team.
https://www.plus2net.com
plus2net.com