Skip to content
← Python for AI/ML · all 50 levels

String slicing

Level 20 of 50 · Data structures

Level 20 of 50

String slicing

explained with your ID card. Watch the reel, then work through it below: run the code, take the quiz, keep the cheat sheet.

📒 Open the cheat sheet
SanaThis form wants only the first 5 digits of my ID card!
TeacherEasy! Cut a piece out of the string. That's slicing!
card.py
card = "35202-1234567-1"

print(card[0:5])
TeacherStart : end. Python cuts from the start, up to the end!
SanaWait, index 5 is the dash. Why isn't it included?
TeacherThe end is NEVER included! 0 to 5 gives exactly 5 characters.

⏸ Pause & predict: what prints?

city = "Islamabad"
print(city[0:5])

Where this leads

Python is step one. Building AI that ships is the rest.

The diploma takes you from zero to deployed computer vision, LLM and agent projects, with engineers who build them for a living. Already code? The bootcamp does it in three months.