A Python string is an object with methods, and almost every method hands back a new string rather than changing the one you called it on. This set covers indexing from either end, splitting a line into fields and joining it back, slicing a value by position, and cleaning a messy field before you compare it. The task runs one line that does all four jobs and asks you to read what it printed.
Each one is marked as you go, and the explanation arrives straight after, which is
the part worth reading.
4 questions, marked as you go.
Tasks
These need your own device. Run the command in Termux, then paste what it printed.
The marking looks at what the output means, so spacing, version numbers and
ordering do not matter. If you have not installed anything yet, the
lesson covers the setup.
Split, join, slice and clean a field
This splits a line from a passwd-style file into fields and picks two of them out, joins a list of words back together with hyphens, slices a prefix, a year and a suffix out of an ID, and cleans a messy field by stripping the spaces and folding it to lower case. Paste all four lines.
Run this in Termux
On your own device. Nothing on this page executes it. The command runs in
your terminal, and this box only reads what you paste back.
The third line has three parts separated by spaces: the prefix, the year, and the last four characters.
the fields were split and the right two picked out
the list was joined back with hyphens
the prefix, the year and the suffix came out of the ID
the field was stripped and folded to lower case
the command actually ran
What a good answer looks like
Four lines. The first is root 0 7, which is the first field, the third field and the number of fields in the line. The second is one-two-three, the list joined with hyphens. The third is INV 2026 0042, the prefix, the year and the last four characters pulled out by position. The fourth is admin, the field with its spaces stripped and its letters folded down. If the third line starts with INV- you used a slice that ran one position too far, which is the usual off-by-one.
Marking your own work
Both halves of this are checked in your browser, with no server involved, so nothing
stops you from pasting output you did not run. The tasks are written so that the
easiest way to pass one is to actually do it and read the result, which is the whole
intention.