method | examples |
---|---|
endswith / startswith |
'hello world'.startswith('he') # -> True |
isalnum / isalpha / isdigit /
islower / isupper / isspace |
|
method | examples |
---|---|
count |
'hello world'.count('l') # -> 3 |
find |
|
index |
Same as find but raises exception if can't find |
Be aware that str
is an immutable type. All the methods bellow return new string (no in place operations).
method | examples |
---|---|
lower / upper / title /
capitalize / swapcase |
|
replace |
'hello world'.replace('world', 'john') # -> 'hello john' |
strip (/ rstrip / lstrip ) |
Removes spaces and new lines from the ends of a string |
method | examples |
---|---|
split (/ rsplit ) |
|
splitlines |
Similar to split('\n') . Read the docs for more info. |
join |
|
A blog post about string formatting
All you will ever need for formating a string.
More string formatting info. Comparing old and new style formatting.
Basic information about string indexing, slicing and a bit further.