|
1 | 1 | # String Methods in Python |
2 | 2 |
|
3 | | -A string (`str`) in Python is a sequence of Unicode code points which |
4 | | -include letters, numbers, symbols, punctuation, etc. Strings |
5 | | -implement all of the [common sequence operations][types seq common], |
6 | | -along with iteration using the `for item in <string>` syntax. |
| 3 | +A `str` is an [immutable sequence][text sequence] of [Unicode code points][unicode code points]. |
| 4 | +These could include letters, diacritical marks, positioning characters, numbers, currecy symbols, emoji, punctuation, space and line break characters, and more. |
7 | 5 |
|
8 | | -Python provides several useful methods that you can use to manipulate |
9 | | -strings. These string methods can be used for cleaning, splitting, translating, |
10 | | -or otherwise working with the `str` type. New strings can be created based |
11 | | -on method arguments, and/or additional information can be returned. Strings |
12 | | -can be concatenated using the `+` operator or with `str.join()`. |
| 6 | +Strings implement all [common sequence operations][common sequence operations], and can be iterated through using `for item in <string>` or `for index, item in enumerate(<string>)` syntax. |
| 7 | +Strings can be concatenated with `+`, or via `<str>.join(<iterable>)`, split via `<str>.split(<separator>)`, and offer multiple types of formatting. |
13 | 8 |
|
14 | | -Some of the more commonly used methods include: |
| 9 | +To further work with strings, Python provides a rich set of [string methods][str-methods] that can assist with searching, cleaning, transforming, translating, and many other operations. |
| 10 | + |
| 11 | +Some of the more commonly used `str` methods include: |
15 | 12 |
|
16 | 13 | - Checking for prefixes/suffixes with `startswith()` and `endswith()` |
17 | 14 | - Altering string casing with methods like `upper()`, `lower()`, and `swapcase()` |
18 | 15 | - Removing leading or trailing characters from a string using `strip()`, `lstrip()`, or `rstrip()` |
19 | 16 | - Replacing substrings with the `replace()` method |
20 | 17 | - Checking for the existence of a substring with `in` |
21 | | -- Concatenating strings with the `+` operator or `str.join()` |
22 | 18 |
|
23 | 19 | The `str` type is _immutable_, so all of these methods will return a new `str` instead of modifying the existing one. |
24 | 20 |
|
25 | | -For more information, you can check out the [official documentation][official documentation]. |
| 21 | +For more information, you can check out the strings [informal tutorial][informal tutorial] or the [`str` docs][str-methods]. |
26 | 22 |
|
27 | | -[types seq common]: https://docs.python.org/3/library/stdtypes.html#typesseq-common |
28 | | -[official documentation]: https://docs.python.org/3/library/stdtypes.html#string-methods |
| 23 | +[common sequence operations]: https://docs.python.org/3/library/stdtypes.html#common-sequence-operations |
| 24 | +[text sequence]: https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str |
| 25 | +[unicode code points]: https://stackoverflow.com/questions/27331819/whats-the-difference-between-a-character-a-code-point-a-glyph-and-a-grapheme |
| 26 | +[informal tutorial]: https://docs.python.org/3/tutorial/introduction.html#strings |
| 27 | +[str-methods]: https://docs.python.org/3/library/stdtypes.html#string-methods |
0 commit comments