| len(s) | the number of characters | int |
| Example: len(word) is 8; len('') is 0. |
| s.upper(), s.lower() | a copy in capital or lower-case letters | str |
| Example: 'Grade 9'.upper() is 'GRADE 9': the digit and the space stay. |
| s.strip() | a copy without the spaces at both ends | str |
| Example: ' ok '.strip() is 'ok', 2 characters instead of 6. |
| s.replace(a, b) | a copy where every a becomes b | str |
| Example: '2025-2026'.replace('-', '/') is '2025/2026'; '1001'.replace('1', '7') is '7007'. |
| s.count(t), s.find(t) | how many times t appears; the index of the first t, or -1 | int |
| Example: word.count('O') is 1, word.find('B') is 3, word.find('Z') is -1. |
| abs(x) | the distance from x to 0 | int or float, like x |
| Example: abs(-12) is 12; abs(4 - 9.5) is 5.5. |
| round(x, n), round(x) | x with n decimals; the nearest whole number | float; int |
| Example: round(3.14159, 2) is 3.14; round(3.7) is 4. |
| max(a, b, ...), min(a, b, ...) | the largest, the smallest of the values | the type of the values |
| Example: max(3, -8, 5) is 5 and min(3, -8, 5) is -8. |
| random.randint(a, b), random.randrange(a, b) | a whole number from a to b; from a to b - 1 | int |
| Example: randint(1, 6) can give back 6, 6 values; randrange(1, 6) never does, 5 values. |
| str(x), int(s), format(x, '.2f') | x as text; the number written in s; x as text with 2 decimals | str; int; str |
| Example: str(25) + '%' is '25%', int('08') + 1 is 9, format(3.5, '.2f') is '3.50'. |
| s.upper() on its own line | a new string, thrown away | s unchanged result lost |
| Example: After word = 'key' and word.upper(), word still holds 'key', 3 lower-case letters. What to do: Store the result: word = word.upper(), or display it: print(word.upper()). |