Pythonの中心()メソッド
Pythonの中心()メソッド
説明
Pythonの中心は()元中央の文字列を返し、長さ幅の新しい文字列をスペースで埋め。 デフォルトはスペース文字です。
文法
中央()メソッドの構文:
str.center(width[, fillchar])
パラメータ
- 幅 - 文字列の幅の合計。
- fillchar - 満たされた文字。
戻り値
このメソッドは、文字列、元の中心を返し、長さ幅の新しい文字列をスペースで埋め。
例
次の例では、中央()インスタンスメソッドを示しています。
#!/usr/bin/python str = "this is string example....wow!!!"; print "str.center(40, 'a') : ", str.center(40, 'a')
次のように上記の出力結果の例は次のとおりです。
str.center(40, 'a') : aaaathis is string example....wow!!!aaaa