GeezerVison is showing github.com — gh-106318: Add examples for str.join() (#140315) · ashm-dev/cpython@00322c7
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: Doc/library/stdtypes.rst +12-1Lines changed: 12 additions & 1 deletion - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -2228,7 +2228,16 @@ expression support in the :mod:`re` module). |
2228 | 2228 | Return a string which is the concatenation of the strings in *iterable*. |
2229 | 2229 | A :exc:`TypeError` will be raised if there are any non-string values in |
2230 | 2230 | *iterable*, including :class:`bytes` objects. The separator between |
2231 | | - elements is the string providing this method. |
| 2231 | + elements is the string providing this method. For example: |
| 2232 | + |
| 2233 | + .. doctest:: |
| 2234 | + |
| 2235 | + >>> ', '.join(['spam', 'spam', 'spam']) |
| 2236 | + 'spam, spam, spam' |
| 2237 | + >>> '-'.join('Python') |
| 2238 | + 'P-y-t-h-o-n' |
| 2239 | + |
| 2240 | + See also :meth:`split`. |
2232 | 2241 |
|
2233 | 2242 |
|
2234 | 2243 | .. method:: str.ljust(width, fillchar=' ', /) |
@@ -2442,6 +2451,8 @@ expression support in the :mod:`re` module). |
2442 | 2451 | >>> " foo ".split(maxsplit=0) |
2443 | 2452 | ['foo '] |
2444 | 2453 |
|
| 2454 | + See also :meth:`join`. |
| 2455 | + |
2445 | 2456 |
|
2446 | 2457 | .. index:: |
2447 | 2458 | single: universal newlines; str.splitlines method |
|