85.16K
AI

string_slicing_grade11

1.

STRING INDEXING & SLICING
GRADE 11
Grade 11 • Python Programming
Access characters • Extract substrings • Solve real-world problems
Learning objectives: 11.2.2.1 | 11.2.2.2
PYTHON • STRING INDEXING & SLICING
P
Y
T
H
O
N
0
1
2
3
4
5
01 / 20

2.

Learning objectives
GRADE 11
11.2.2.1 Perform access to the elements of strings
11.2.2.2 Use slicers to process the string
Success criteria: index correctly, explain boundaries, solve applied tasks
PYTHON • STRING INDEXING & SLICING
P
Y
T
H
O
N
0
1
2
3
4
5
02 / 20

3.

Lesson roadmap • 80 minutes
GRADE 11
Starter / prediction — 8 min
Indexing & negative indices — 15 min
Slicing demonstration — 17 min
Applied practice — 30 min
Review & exit ticket — 10 min
PYTHON • STRING INDEXING & SLICING
P
Y
T
H
O
N
0
1
2
3
4
5
03 / 20

4.

Starter: predict before running
GRADE 11
What will each expression print?
word = 'PYTHON'
print(word[0])
Discuss
your prediction with a partner.
print(word[-1])
print(word[2])
P
N
T
Remember: the first index is 0.
PYTHON • STRING INDEXING & SLICING
04 / 20

5.

String indexing: one character
P
Y
T
H
O
N
0
1
2
3
4
5
GRADE 11
Positive indices start at 0; negative indices start at -1.
word = 'PYTHON'
# letters:
P
Y
T
H
O
N
# positive:
0
1
2
3
4
5
# negative: -6 -5 -4 -3 -2 -1
print(word[1])
PYTHON • STRING INDEXING & SLICING
# Y
05 / 20

6.

Indexing: common mistakes
GRADE 11
An index returns ONE character.
An invalid index raises IndexError.
Strings are immutable: you cannot replace a character directly.
word = 'PYTHON'
print(word[5])
# print(word[6])
PYTHON • STRING INDEXING & SLICING
# N
# IndexError
06 / 20

7.

Slicing: [start : stop : step]
GRADE 11
start = first included index
stop = boundary NOT included
step = how far to move each time
word = 'PYTHON'
print(word[1:4])
print(word[0:6:2])
PYTHON • STRING INDEXING & SLICING
# YTH
# PTO
07 / 20

8.

Visualize the slice
P
Y
T
H
O
N
0
1
2
3
4
5
GRADE 11
word[1:4] selects positions 1, 2 and 3.
word = 'PYTHON'
print(word[1:4])
# YTH
print(word[:3])
# PYT
print(word[3:])
# HON
PYTHON • STRING INDEXING & SLICING
08 / 20

9.

Negative indices & reverse slices
P
R
O
G
R
A
M
M
I
N
G
-11
-10
-9
-8
-7
-6
-5
-4
-3
-2
-1
GRADE 11
# ming
For a reverse slice, start must be to the right of stop.
word = 'programming'
print(word[-4:])
print(word[::-1])
print(word[-1:2:-1])
PYTHON • STRING INDEXING & SLICING
# ming
# gnimmargorp
# gnimmarg
09 / 20

10.

Check for understanding
C
O
M
P
U
T
E
R
0
1
2
3
4
5
6
7
GRADE 11
s = 'COMPUTER'
print(s[2:5])
print(s[-3:])
print(s[::2])
print(s[::-1])
Pair discussion • 3 minutes
PYTHON • STRING INDEXING & SLICING
10 / 20

11.

Applied task 1 • Student ID
GRADE 11
A student ID stores year (4 chars), class (3), number (3).
Extract and print all three fields.
student_id = '2026A12045'
2026
# Expected: 2026 | A12 | 045
A12 • 045
Use only slicing and print().
PYTHON • STRING INDEXING & SLICING
11 / 20

12.

Applied task 2 • Bank card
GRADE 11
Show only the last 4 digits of a 16-digit card number.
Replace the first 12 digits with asterisks.
card = '4400123456789012'
# Expected: ************9012
•••• •••
9012
Use slicing and string concatenation.
PYTHON • STRING INDEXING & SLICING
12 / 20

13.

Applied task 3 • Date converter
GRADE 11
Convert YYYY-MM-DD into DD/MM/YYYY.
date = '2026-11-17'
# Expected: 17/11/2026
No split(), loops or lists.
17
date = '2026-11-17'
# Expected: 17/11/2026
PYTHON • STRING INDEXING & SLICING
13 / 20

14.

Applied task 4 • Parcel tracking
GRADE 11
Country = first 2; warehouse = next 4; parcel = last 6.
Create a short code: country + last 3 digits.
tracking = 'KZ2045123456'
# Expected: KZ | 2045 | 123456
KZ
# Short code: KZ456
PYTHON • STRING INDEXING & SLICING
14 / 20

15.

Applied task 5 • Palindrome check
GRADE 11
Check whether the text reads the same backwards.
Print a Boolean result (True or False).
↶
password = 'level'
# Expected: True
# Also test: 'python' -> False
Hint: compare the original string with its reverse.
PYTHON • STRING INDEXING & SLICING
15 / 20

16.

Applied task 6 • Secret decoder
GRADE 11
Every real character is followed by an extra character.
Decode using ONE slicing expression.
secret = 'PxYxTxHxOxN'
PxYx
# Expected: PYTHON
TxHx
Challenge: explain why your step works.
PYTHON • STRING INDEXING & SLICING
16 / 20

17.

Challenge 7 • Secure access code
GRADE 11
A security gate receives an access code with fixed-length fields.
code = "KZ-2026-ABCD-7890"
1. Extract the country, year, department and PIN.
2. Create a masked code: KZ-****-ABCD-7890.
3. Print the PIN in reverse order.
Rules: slicing + concatenation only • no split(), loops or lists
PYTHON • STRING SLICING • APPLIED CHALLENGE
17

18.

Challenge 8 • System log decoder
GRADE 11
A monitoring system saves one log entry as a compact string.
log = "20261117_143025_ERROR"
1. Display the date as 17/11/2026.
2. Display the time as 14:30:25.
3. Extract the status ERROR.
4. Build a summary: ERROR at 14:30 on 17/11/2026.
Extension: display the date in reverse digit order.
PYTHON • STRING SLICING • APPLIED CHALLENGE
18

19.

Independent challenge
GRADE 11
P
R
O
G
R
A
M
M
I
N
G
-11
-10
-9
-8
-7
-6
-5
-4
-3
-2
-1
word = 'programming'
print(word[-1:2:-1])
Extension: create a different reverse slice.
PYTHON • STRING INDEXING & SLICING
17 / 20

20.

Exit ticket • 5 minutes
GRADE 11
1. What does the stop index mean?
2. How do you select the last 3 characters?
3. How do you reverse a string?
4. Write one practical use of slicing.
PYTHON • STRING INDEXING & SLICING
18 / 20

21.

Teacher answer key • 1
GRADE 11
Starter: P, N, T
Check: MPU, TER, CMUE, RETUPMOC
Challenge: gnimmarg
student_id[:4]
# 2026
student_id[4:7]
# A12
student_id[7:]
# 045
'*' * 12 + card[-4:] # ************9012
PYTHON • STRING INDEXING & SLICING
19 / 20

22.

Teacher answer key • 2
GRADE 11
Date: date[8:] + "/" + date[5:7] + "/" + date[:4]
Tracking: [:2], [2:6], [6:], [:2] + [-3:]
Palindrome: password == password[::-1]
Decoder: secret[::2]
PYTHON • STRING INDEXING & SLICING
20 / 20

23.

Teacher answer key • challenges
GRADE 11
Challenge 7
code[:2]
code[3:7]
code[8:12]
code[-4:]
code[:3] + "****" + code[7:]
code[::-1][:4]
or
code[-1:-5:-1]
Challenge 8
date = log[6:8] + "/" + log[4:6] + "/" + log[:4]
time = log[9:11] + ":" + log[11:13] + ":" + log[13:15]
status = log[16:]
summary = status + " at " + time[:5] + " on " + date
PYTHON • STRING SLICING • APPLIED CHALLENGE
23
English     Русский Rules