Space Python Loading Python…

String Indexing and Slicing

 
0:00 / 0:00

Challenge

Practise what this example shows with these challenges.

Date and time from a timestamp

Write the codeEasy 2 stages

Slice the date and the time of day out of an ISO timestamp like 2026-03-14T09:30:05Z, then rebuild it in the day.month.year format used in Poland and much of Europe.

Start the challenge

Off-by-one slice

Fix the codeEasy 3 stages

A slice meant to take the number from the container tag CG-0042 gives -004. Predict it, work out where indexes start and where a slice ends, fix it, then slice a sample label yourself.

Start the challenge

Redact the access code

Write the codeMedium 2 stages

Replace all but the last four characters of an access code with * using len(), slicing and string repetition, then find a code inside a log line and mask it there before the line is saved.

Start the challenge

Strings don't change

Fix the codeEasy 3 stages

code[0] = "X" stops with a TypeError, because Python strings can't be changed. Predict the crash, find out what methods and slices really give, build a new string instead, then swap a letter in the middle of a code.

Start the challenge

Discussion

Stuck on this example or want to go further? Ask here, or see what others asked.

Log in to ask and reply.

script.py
PythonLn 1, Col 1Spaces: 4
Loading the Python environment…

Separate arguments with commas. They're passed on every Run as sys.argv[1:].