All courses › Programming with Python › String methods
String methods
Strings have built-in methods like .upper(), .split(sep) and .count(sub). split divides a string at a separator and returns a list of substrings. Methods always return a new value and never change the original string.
splits at character , gives a list
number of times occurs in
Symbols
| a string | ||
| separator | ||
| the substring counted |
Example
"a,b,c".split(",") gives ['a', 'b', 'c'].
"termo".count("m") gives 1.
Strings are immutable:
Practise functions and data structures for free →
s.upper() creates a new string, it does not change s.← Dictionary (dict) · Mutable objects and references →
Part of Programming with Python: Functions and data structures.