Data Structures: Strings, Lists, Tuples and Dictionaries – Grade 13 A/L ICT Notes 9.10

© 2026 schoolict.net (Ruwan Mangala Suraweera)

9.10 Data Structures: Strings, Lists, Tuples and Dictionariesදත්ත ව්‍යුහ: තන්තු, ලැයිස්තු, Tuples සහ ශබ්දකෝෂ

Grade 13 A/L ICT · Lesson 913 ශ්‍රේණිය A/L ICT · පාඩම 9

Prints all tabs in the language you are reading. Use “Save as PDF” in the print window to keep a copy.ඔබ කියවන භාෂාවෙන් සියලු tabs මුද්‍රණය වේ. පිටපතක් තියාගන්න print window එකේ “Save as PDF” තෝරන්න.
🎬Video coming soon in this language. Switch language to watch the other video.මේ භාෂාවෙන් වීඩියෝව ඉක්මනින් එනවා. අනෙක් වීඩියෝව බලන්න භාෂාව මාරු කරන්න.

In this videoමේ වීඩියෝවේ

  • Strings hold text and cannot be changed.තන්තු පෙළ රඳවයි; වෙනස් නොවේ.
  • Lists are ordered and changeable.ලැයිස්තු පිළිවෙළ සහ වෙනස් කළ හැක.
  • Tuples are ordered and fixed.Tuples පිළිවෙළ සහ ස්ථිරයි.
  • Dictionaries map keys to values.ශබ්දකෝෂ keys අගයන්ට සම්බන්ධ කරයි.
  • Indexes start at 0; slices exclude the stop.Index 0 සිට; slice අවසානය ඇතුළත් නොවේ.
Data structureStringListTupleDictionaryIndexSlice

Notesසටහන්

Syllabus 9.10. A data structure stores many values under one name. Python has strings (text), lists (changeable sequences), tuples (fixed sequences) and dictionaries (key → value pairs). You use indexing, slicing and methods to work with them.විෂය නිර්දේශය 9.10. දත්ත ව්‍යුහයක් එක් නමක් යටතේ අගයන් බොහොමයක් ගබඩා කරයි. Python හි තන්තු (පෙළ), ලැයිස්තු (වෙනස් කළ හැකි අනුක්‍රම), tuples (ස්ථිර අනුක්‍රම) සහ ශබ්දකෝෂ (key → value යුගල) ඇත. ඒවා සමඟ indexing, slicing සහ methods භාවිත කරමු.

1. Four structures1. ව්‍යුහ හතර

Python data structuresString“Sri Lanka”ordered · immutableList[45, 62, 78]ordered · mutableTuple(6, 9)ordered · immutableDictionary{“red”: 3}key → value · mutableIndex from 0: s[0] is the first item, s[-1] the last; s[4:9] slices items 4 to 8.
String, list, tuple and dictionaryතන්තු, ලැයිස්තු, tuple සහ ශබ්දකෝෂ
Structureව්‍යුහයBracketsවරහන්Ordered?පිළිවෙළ?Changeable?වෙනස් කළ හැකිද?
Stringතන්තුව” “” “Yesඔව්Noනැත
Listලැයිස්තුව[ ][ ]Yesඔව්Yesඔව්
TupleTuple( )( )Yesඔව්Noනැත
Dictionaryශබ්දකෝෂය{key: value}{key: value}By insertionඇතුළත් කිරීම අනුවYesඔව්

🐍 Strings, lists, tuples and dictionariesතන්තු, ලැයිස්තු, tuples සහ ශබ්දකෝෂ

s = "Sri Lanka"
print(s[0], s[-1], s[4:9], len(s), s.upper())

marks = [45, 78, 62]
marks.append(90)
marks.sort()
print(marks, marks[1:3], sum(marks))

point = (6, 9)                 # tuple: cannot be changed
print(point[0] + point[1])

words = "red blue red green red".split()
freq = {}
for w in words:
    freq[w] = freq.get(w, 0) + 1
print(freq)
print(sorted(freq.items()))

▶ Outputප්‍රතිදානය

S a Lanka 9 SRI LANKA
[45, 62, 78, 90] [62, 78] 275
15
{'red': 3, 'blue': 1, 'green': 1}
[('blue', 1), ('green', 1), ('red', 3)]
🧮 Worked exampleවිසඳූ උදාහරණය Explain s[4:9], the sorted list and the word counts.s[4:9], අනුපිළිවෙළ ලැයිස්තුව සහ වචන ගණන් පැහැදිලි කරන්න.
“Sri Lanka” has 9 characters (index 0–8); s[4:9] takes 4 to 8 = Lanka. After append(90) and sort() the list is [45, 62, 78, 90], the slice [1:3] is [62, 78] and the sum is 275. The dictionary counts red 3, blue 1, green 1.“Sri Lanka” අක්ෂර 9 (0–8); s[4:9] = Lanka. append, sort පසු [45, 62, 78, 90]; [1:3] = [62, 78]; එකතුව 275. red 3, blue 1, green 1.
  • List methods: append, insert, remove, pop, sort, len().ලැයිස්තු methods: append, insert, remove, pop, sort, len().
  • String methods: upper, lower, split, strip, find, replace.තන්තු methods: upper, lower, split, strip, find, replace.
  • Dictionary: d[key], d.get(key, default), d.keys(), d.values(), d.items().ශබ්දකෝෂ: d[key], d.get(), keys(), values(), items().
💡 Negative indexes count from the end: s[-1] is the last item.ඍණ index අගින් ගණන් කරයි: s[-1] අවසාන අයිතමයයි.
🚀 Beyond the syllabus (2026 update)🚀 විෂය නිර්දේශයෙන් ඔබ්බට (2026 යාවත්කාලීනය) Not required for the exam – read for interest.විභාගයට අවශ්‍ය නැත – දැනුම සඳහා කියවන්න. JSON – the format most 2026 web APIs use – maps directly to Python dictionaries and lists.2026 web API භාවිත කරන JSON සෘජුවම Python ශබ්දකෝෂ සහ ලැයිස්තුවලට ගැළපේ.

Key Wordsප්‍රධාන පද

Data structureදත්ත ව්‍යුහය
Way of storing many values under one name.අගයන් බොහොමයක් එක් නමක් යටතේ ගබඩා කිරීම.
Stringතන්තුව
Ordered immutable sequence of characters.අක්ෂරවල පිළිවෙළ වෙනස් කළ නොහැකි අනුක්‍රමය.
Listලැයිස්තුව
Ordered mutable sequence written in square brackets.හතරැස් වරහන් තුළ ලියන වෙනස් කළ හැකි අනුක්‍රමය.
TupleTuple
Ordered immutable sequence written in round brackets.රවුම් වරහන් තුළ වෙනස් කළ නොහැකි අනුක්‍රමය.
Dictionaryශබ්දකෝෂය
Collection of key and value pairs.key සහ value යුගල එකතුව.
IndexIndex
Position number of an item starting from 0.0 සිට ආරම්භ වන අයිතමයේ ස්ථාන අංකය.
SliceSlice
Part of a sequence taken with start:stop.start:stop මගින් ගන්නා අනුක්‍රම කොටස.
Mutableවෙනස් කළ හැකි
Can be changed after it is created.සෑදූ පසු වෙනස් කළ හැකි.
Immutableවෙනස් කළ නොහැකි
Cannot be changed after it is created.සෑදූ පසු වෙනස් කළ නොහැකි.
MethodMethod
Function that belongs to an object such as append.append වැනි වස්තුවකට අයත් ශ්‍රිතය.
KeyKey
Unique label used to look up a value in a dictionary.ශබ්දකෝෂයක අගයක් සොයන අනන්‍ය ලේබලය.
Concatenationසම්බන්ධ කිරීම
Joining strings or lists with +.+ මගින් තන්තු හෝ ලැයිස්තු එකතු කිරීම.

Sample Q&Aආදර්ශ ප්‍රශ්න සහ පිළිතුරු

1List vs tuple?ලැයිස්තුව සහ tuple?

Answerපිළිතුර: Lists can change; tuples cannot.ලැයිස්තු වෙනස් වේ; tuple නොවේ.

2s[0] and s[-1] for “Sri Lanka”?s[0], s[-1]?

Answerපිළිතුර: S and a.S සහ a.

3List after append(90) and sort()?append, sort පසු?

Answerපිළිතුර: [45, 62, 78, 90].[45, 62, 78, 90].

4How many times does red appear?red වාර?

Answerපිළිතුර: 3.3.

5What does freq.get(w, 0) do?freq.get(w, 0)?

Answerපිළිතුර: Returns the count or 0 if w is not yet a key.ගණන හෝ 0.

6Why use a tuple for a point?point සඳහා tuple ඇයි?

Answerපිළිතුර: The coordinates should not change.ඛණ්ඩාංක වෙනස් නොවිය යුතුය.

MCQබහුවරණ ප්‍රශ්න

Choose the correct answer for each question.සෑම ප්‍රශ්නයකටම නිවැරදි පිළිතුර තෝරන්න.

Scoreලකුණු: 0 / 20

1For s = “Sri Lanka”, s[4:9] iss[4:9]

✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: E

Index 4 to 8.4 සිට 8.

2len(“Sri Lanka”) islen

✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: C

Space counts.හිස්තැනද ගණන් වේ.

3After append(90) and sort(), marks[1:3] is[1:3]

✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: B

Items 1 and 2.1 සහ 2.

4sum of [45, 62, 78, 90] issum

✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: C

Total.එකතුව.

5Which structure cannot be changed after creation?වෙනස් නොවන

✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: A

Tuple.Tuple.

6In the word count, freq[“red”] isred

✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: C

Three times.තුන් වරක්.

7Key → value pairs are stored in akey → value

✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: B

Dictionary.ශබ්දකෝෂය.

8point[0] + point[1] for (6, 9) is(6, 9)

✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: E

6 + 9.6 + 9.

9Which term means: “Way of storing many values under one name”?“අගයන් බොහොමයක් එක් නමක් යටතේ ගබඩා කිරීම” යන්නෙන් අදහස් වන පදය කුමක්ද?

✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: A

Data structure – Way of storing many values under one name.දත්ත ව්‍යුහය – අගයන් බොහොමයක් එක් නමක් යටතේ ගබඩා කිරීම.

10Which term means: “Ordered immutable sequence of characters”?“අක්ෂරවල පිළිවෙළ වෙනස් කළ නොහැකි අනුක්‍රමය” යන්නෙන් අදහස් වන පදය කුමක්ද?

✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: A

String – Ordered immutable sequence of characters.තන්තුව – අක්ෂරවල පිළිවෙළ වෙනස් කළ නොහැකි අනුක්‍රමය.

11Which term means: “Ordered mutable sequence written in square brackets”?“හතරැස් වරහන් තුළ ලියන වෙනස් කළ හැකි අනුක්‍රමය” යන්නෙන් අදහස් වන පදය කුමක්ද?

✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: D

List – Ordered mutable sequence written in square brackets.ලැයිස්තුව – හතරැස් වරහන් තුළ ලියන වෙනස් කළ හැකි අනුක්‍රමය.

12Which term means: “Ordered immutable sequence written in round brackets”?“රවුම් වරහන් තුළ වෙනස් කළ නොහැකි අනුක්‍රමය” යන්නෙන් අදහස් වන පදය කුමක්ද?

✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: C

Tuple – Ordered immutable sequence written in round brackets.Tuple – රවුම් වරහන් තුළ වෙනස් කළ නොහැකි අනුක්‍රමය.

13Which term means: “Collection of key and value pairs”?“key සහ value යුගල එකතුව” යන්නෙන් අදහස් වන පදය කුමක්ද?

✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: B

Dictionary – Collection of key and value pairs.ශබ්දකෝෂය – key සහ value යුගල එකතුව.

14Which term means: “Position number of an item starting from 0”?“0 සිට ආරම්භ වන අයිතමයේ ස්ථාන අංකය” යන්නෙන් අදහස් වන පදය කුමක්ද?

✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: B

Index – Position number of an item starting from 0.Index – 0 සිට ආරම්භ වන අයිතමයේ ස්ථාන අංකය.

15Which term means: “Part of a sequence taken with start:stop”?“start:stop මගින් ගන්නා අනුක්‍රම කොටස” යන්නෙන් අදහස් වන පදය කුමක්ද?

✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: D

Slice – Part of a sequence taken with start:stop.Slice – start:stop මගින් ගන්නා අනුක්‍රම කොටස.

16Which term means: “Can be changed after it is created”?“සෑදූ පසු වෙනස් කළ හැකි” යන්නෙන් අදහස් වන පදය කුමක්ද?

✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: A

Mutable – Can be changed after it is created.වෙනස් කළ හැකි – සෑදූ පසු වෙනස් කළ හැකි.

17Which term means: “Cannot be changed after it is created”?“සෑදූ පසු වෙනස් කළ නොහැකි” යන්නෙන් අදහස් වන පදය කුමක්ද?

✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: E

Immutable – Cannot be changed after it is created.වෙනස් කළ නොහැකි – සෑදූ පසු වෙනස් කළ නොහැකි.

18Which term means: “Function that belongs to an object such as append”?“append වැනි වස්තුවකට අයත් ශ්‍රිතය” යන්නෙන් අදහස් වන පදය කුමක්ද?

✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: D

Method – Function that belongs to an object such as append.Method – append වැනි වස්තුවකට අයත් ශ්‍රිතය.

19Which term means: “Unique label used to look up a value in a dictionary”?“ශබ්දකෝෂයක අගයක් සොයන අනන්‍ය ලේබලය” යන්නෙන් අදහස් වන පදය කුමක්ද?

✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: E

Key – Unique label used to look up a value in a dictionary.Key – ශබ්දකෝෂයක අගයක් සොයන අනන්‍ය ලේබලය.

20Which term means: “Joining strings or lists with +”?“+ මගින් තන්තු හෝ ලැයිස්තු එකතු කිරීම” යන්නෙන් අදහස් වන පදය කුමක්ද?

✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: D

Concatenation – Joining strings or lists with +.සම්බන්ධ කිරීම – + මගින් තන්තු හෝ ලැයිස්තු එකතු කිරීම.

MCQ answer keyMCQ පිළිතුරු

  1. E – Index 4 to 8.4 සිට 8.
  2. C – Space counts.හිස්තැනද ගණන් වේ.
  3. B – Items 1 and 2.1 සහ 2.
  4. C – Total.එකතුව.
  5. A – Tuple.Tuple.
  6. C – Three times.තුන් වරක්.
  7. B – Dictionary.ශබ්දකෝෂය.
  8. E – 6 + 9.6 + 9.
  9. A – Data structure – Way of storing many values under one name.දත්ත ව්‍යුහය – අගයන් බොහොමයක් එක් නමක් යටතේ ගබඩා කිරීම.
  10. A – String – Ordered immutable sequence of characters.තන්තුව – අක්ෂරවල පිළිවෙළ වෙනස් කළ නොහැකි අනුක්‍රමය.
  11. D – List – Ordered mutable sequence written in square brackets.ලැයිස්තුව – හතරැස් වරහන් තුළ ලියන වෙනස් කළ හැකි අනුක්‍රමය.
  12. C – Tuple – Ordered immutable sequence written in round brackets.Tuple – රවුම් වරහන් තුළ වෙනස් කළ නොහැකි අනුක්‍රමය.
  13. B – Dictionary – Collection of key and value pairs.ශබ්දකෝෂය – key සහ value යුගල එකතුව.
  14. B – Index – Position number of an item starting from 0.Index – 0 සිට ආරම්භ වන අයිතමයේ ස්ථාන අංකය.
  15. D – Slice – Part of a sequence taken with start:stop.Slice – start:stop මගින් ගන්නා අනුක්‍රම කොටස.
  16. A – Mutable – Can be changed after it is created.වෙනස් කළ හැකි – සෑදූ පසු වෙනස් කළ හැකි.
  17. E – Immutable – Cannot be changed after it is created.වෙනස් කළ නොහැකි – සෑදූ පසු වෙනස් කළ නොහැකි.
  18. D – Method – Function that belongs to an object such as append.Method – append වැනි වස්තුවකට අයත් ශ්‍රිතය.
  19. E – Key – Unique label used to look up a value in a dictionary.Key – ශබ්දකෝෂයක අගයක් සොයන අනන්‍ය ලේබලය.
  20. D – Concatenation – Joining strings or lists with +.සම්බන්ධ කිරීම – + මගින් තන්තු හෝ ලැයිස්තු එකතු කිරීම.

Structured Questionsව්‍යුහගත ප්‍රශ්න

1Compare strings, lists, tuples and dictionaries.ව්‍යුහ හතර සසඳන්න. (4 marksලකුණු 4)

Show model answerආදර්ශ පිළිතුර පෙන්වන්න
Brackets; ordered; mutable or not; key → value.වරහන්; පිළිවෙළ; වෙනස්; key.

2Give the output of s[0], s[-1], s[4:9] and s.upper() for “Sri Lanka”.ප්‍රතිදානය. (4 marksලකුණු 4)

Show model answerආදර්ශ පිළිතුර පෙන්වන්න
S; a; Lanka; SRI LANKA.S; a; Lanka; SRI LANKA.

3Write code to add a mark, sort the list and print the total.ලැයිස්තු කේතය. (3 marksලකුණු 3)

Show model answerආදර්ශ පිළිතුර පෙන්වන්න
marks.append(90); marks.sort(); print(sum(marks)).append; sort; sum.

4Write code that counts words using a dictionary.වචන ගණන් කිරීම. (4 marksලකුණු 4)

Show model answerආදර්ශ පිළිතුර පෙන්වන්න
split(); for each word; freq[w] = freq.get(w, 0) + 1; print.split; for; get.

5Explain mutable and immutable with examples.mutable සහ immutable. (2 marksලකුණු 2)

Show model answerආදර්ශ පිළිතුර පෙන්වන්න
List mutable (append); string/tuple immutable.ලැයිස්තුව; tuple.

🎮 Game🎮 ක්‍රීඩා

Pick a game. Each one uses words from this lesson.ක්‍රීඩාවක් තෝරන්න. හැම එකක්ම මේ පාඩමේ වචන පාවිච්චි කරනවා.

Summary & Downloadsසාරාංශය සහ බාගත කිරීම්

Key pointsප්‍රධාන කරුණු

  • Strings hold text and cannot be changed.තන්තු පෙළ රඳවයි; වෙනස් නොවේ.
  • Lists are ordered and changeable.ලැයිස්තු පිළිවෙළ සහ වෙනස් කළ හැක.
  • Tuples are ordered and fixed.Tuples පිළිවෙළ සහ ස්ථිරයි.
  • Dictionaries map keys to values.ශබ්දකෝෂ keys අගයන්ට සම්බන්ධ කරයි.
  • Indexes start at 0; slices exclude the stop.Index 0 සිට; slice අවසානය ඇතුළත් නොවේ.

Downloadsබාගත කිරීම්

Full Lesson 9 PDFසම්පූර්ණ පාඩම 9 PDF: English · සිංහල

Next noteඊළඟ සටහන 9.11 →

© 2026 schoolict.net (Ruwan Mangala Suraweera). All rights reserved.සියලු හිමිකම් ඇවිරිණි.

Resource Book Lesson Note Download Questions Syllabus Sinhala LMS Simulator Tool