Python String center() is a built-in method that “creates and returns a new string padded with the specified character”. The string center() method in python provides padding with a specific character, which can be space or any other character. The method returns a new string that is padded.
The center() method takes two arguments:
width: length of the string with padded characters.
fillchar: padding character.
The fillchar argument is optional. If it’s not provided, space is taken as a default argument.
s1 ='hello' s2 = s1.center(7, '#') print(s2)
It returns a string padded with the specified character. It doesn’t change the value of the main string; it stores the padded string in another variable.
s1 = 'hello this is a string' s2 = s1.center(40, "*") print(s2)
*********hello this is a string*********
string = "I am AlienX" string2 = string.center(30, "#") print(string2)
#########I am AlienX##########
1 thought on “Python String center() Method”
Hey Admin, I was just wandering something about laravel and entered your site.
Just as usual I was going through few of your article, and thanks, I got what I was looking for.
Then I just thought of checking your site security a bit, then I noticed you are using wordpress and your site isn’t secure I mean your security is way too low. No any protection over admin login huh :/ and then I hit https://appdividend.com/users and I was able to get all your usersnames and that shouldn’t happen cause it could lead to some sorts of brute-force attacks. So you helped me on my thing so as a script kiddie and partly noob security researcher I also wanna give a bit some sorts of advice :). Protect your site site login with 2 factor authentication and litmit the login attempt as it could lead to bruteforce attacks and all, remove unnecessary plugins, and hide your wp-admin login by redirecting it over some other page using some plugins or manual code so that only you could access it.
Also there are lot of things you guys need to fix up, for now that much should work good.
Once again thank you for the article it helped me a lot 🙂
Have a good day