This article mainly introduces the center () method used in Python for handling strings, which is the basic knowledge in Python, and needs friends to refer to the
The center () method returns a string centered on the length width. Padding is done by using Specifiedfillchar. The default padding character is a space.
The following is the syntax for the Center () method:
|1||Str.center (width[, Fillchar])|
Width-This is the total width of the string.
Fillchar--This is the filler character.
This method returns a string centered on the length width.
The following example shows the use of the Center () method.
|1 2 3 4 5||#!/usr/bin/python str = "This is string Example....wow!!!"; Print "Str.center (b, ' a '):", Str.center (+, ' a ')|
When we run the above program, it produces the following results:
|1||Str.center (+, ' a '): Aaaathis is string EXAMPLE....WOW!!! Aaaa|