]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.14] gh-106318: Add example for `str.center()` (GH-134518) (#134571)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Fri, 23 May 2025 09:51:17 +0000 (11:51 +0200)
committerGitHub <noreply@github.com>
Fri, 23 May 2025 09:51:17 +0000 (09:51 +0000)
Co-authored-by: Blaise Pabon <blaise@gmail.com>
Doc/library/stdtypes.rst

index 3486a18b5cb1f0fe225c7cecf36c2f4a3ef5ccdc..ce613476854110f52b67b82ed74ff4c3b6584be7 100644 (file)
@@ -1788,8 +1788,14 @@ expression support in the :mod:`re` module).
 
    Return centered in a string of length *width*. Padding is done using the
    specified *fillchar* (default is an ASCII space). The original string is
-   returned if *width* is less than or equal to ``len(s)``.
-
+   returned if *width* is less than or equal to ``len(s)``.  For example::
+
+      >>> 'Python'.center(10)
+      '  Python  '
+      >>> 'Python'.center(10, '-')
+      '--Python--'
+      >>> 'Python'.center(4)
+      'Python'
 
 
 .. method:: str.count(sub[, start[, end]])