How to use the Python String Methods Playground
- 1. Type a stringSpaces at the ends are kept, so you can test strip().
- 2. Pick a methodTypical arguments fill in; change them to experiment.
- 3. RunSee the exact repr() of the result, its type and its length.
Methods covered
- Case: upper, lower, title, capitalize, swapcase, casefold.
- Trimming: strip, lstrip, rstrip, removeprefix, removesuffix.
- Splitting: split, rsplit, splitlines, partition, rpartition.
- Searching: find, rfind, index, count, startswith, endswith, replace.
- Checks: isalpha, isdigit, isnumeric, isalnum, isspace, isupper, islower, istitle.
- Padding and others: center, ljust, rjust, zfill, encode, expandtabs, format, join.
Results are shown with repr(), the way Python's console shows them, so you can see quotes, \n line breaks and leading spaces that print() would hide. Because Python strings are immutable, the original string is listed too, always unchanged.
Worked example
The sample string is ' Learn Python with Uncodemy! ', 31 characters with two spaces at each end. .strip() returns 'Learn Python with Uncodemy!', type str, length 27. Then try:
.split()returns['Learn', 'Python', 'with', 'Uncodemy!'], a list of 4. Extra spaces are ignored when no separator is given..find('Python')returns 8, and.find('Java')returns -1, while.index('Java')raises a ValueError..replace('Python', 'Py')changes every match; add a third argument to limit how many.- For
.join, the string is the separator: with s set to ', ' and the argument ['a', 'b', 'c'], you get 'a, b, c'.
The code runs in real Python 3 (Pyodide), loaded once in your browser, so the results are exactly what Python gives.
Frequently asked questions
What is the difference between isdigit and isnumeric?
isnumeric also accepts characters like ½ and Devanagari digits such as ३. isdecimal is the strictest of the three.
Why doesn't strip() change my string?
Strings can't be changed in place. Assign the result: s = s.strip().
Can I chain methods?
In your own code, yes: s.strip().lower().split(). Here, run one method at a time to see each step.
Do I have to pay for the python string methods playground?
No, it is free. Your first run asks for your name and WhatsApp number one time only. Then the python string methods playground and all other Uncodemy tools stay open for you with no form.