© 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
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 අවසානය ඇතුළත් නොවේ.
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. ව්යුහ හතර
| 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)]“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().
Key Wordsප්රධාන පද
Sample Q&Aආදර්ශ ප්රශ්න සහ පිළිතුරු
1List vs tuple?ලැයිස්තුව සහ tuple?
2s[0] and s[-1] for “Sri Lanka”?s[0], s[-1]?
3List after append(90) and sort()?append, sort පසු?
4How many times does red appear?red වාර?
5What does freq.get(w, 0) do?freq.get(w, 0)?
6Why use a tuple for a point?point සඳහා tuple ඇයි?
MCQබහුවරණ ප්රශ්න
Choose the correct answer for each question.සෑම ප්රශ්නයකටම නිවැරදි පිළිතුර තෝරන්න.
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 පිළිතුරු
- E – Index 4 to 8.4 සිට 8.
- C – Space counts.හිස්තැනද ගණන් වේ.
- B – Items 1 and 2.1 සහ 2.
- C – Total.එකතුව.
- A – Tuple.Tuple.
- C – Three times.තුන් වරක්.
- B – Dictionary.ශබ්දකෝෂය.
- E – 6 + 9.6 + 9.
- A – Data structure – Way of storing many values under one name.දත්ත ව්යුහය – අගයන් බොහොමයක් එක් නමක් යටතේ ගබඩා කිරීම.
- A – String – Ordered immutable sequence of characters.තන්තුව – අක්ෂරවල පිළිවෙළ වෙනස් කළ නොහැකි අනුක්රමය.
- D – List – Ordered mutable sequence written in square brackets.ලැයිස්තුව – හතරැස් වරහන් තුළ ලියන වෙනස් කළ හැකි අනුක්රමය.
- C – Tuple – Ordered immutable sequence written in round brackets.Tuple – රවුම් වරහන් තුළ වෙනස් කළ නොහැකි අනුක්රමය.
- B – Dictionary – Collection of key and value pairs.ශබ්දකෝෂය – key සහ value යුගල එකතුව.
- B – Index – Position number of an item starting from 0.Index – 0 සිට ආරම්භ වන අයිතමයේ ස්ථාන අංකය.
- D – Slice – Part of a sequence taken with start:stop.Slice – start:stop මගින් ගන්නා අනුක්රම කොටස.
- A – Mutable – Can be changed after it is created.වෙනස් කළ හැකි – සෑදූ පසු වෙනස් කළ හැකි.
- E – Immutable – Cannot be changed after it is created.වෙනස් කළ නොහැකි – සෑදූ පසු වෙනස් කළ නොහැකි.
- D – Method – Function that belongs to an object such as append.Method – append වැනි වස්තුවකට අයත් ශ්රිතය.
- E – Key – Unique label used to look up a value in a dictionary.Key – ශබ්දකෝෂයක අගයක් සොයන අනන්ය ලේබලය.
- D – Concatenation – Joining strings or lists with +.සම්බන්ධ කිරීම – + මගින් තන්තු හෝ ලැයිස්තු එකතු කිරීම.
Structured Questionsව්යුහගත ප්රශ්න
1Compare strings, lists, tuples and dictionaries.ව්යුහ හතර සසඳන්න. (4 marksලකුණු 4)
Show model answerආදර්ශ පිළිතුර පෙන්වන්න
2Give the output of s[0], s[-1], s[4:9] and s.upper() for “Sri Lanka”.ප්රතිදානය. (4 marksලකුණු 4)
Show model answerආදර්ශ පිළිතුර පෙන්වන්න
3Write code to add a mark, sort the list and print the total.ලැයිස්තු කේතය. (3 marksලකුණු 3)
Show model answerආදර්ශ පිළිතුර පෙන්වන්න
4Write code that counts words using a dictionary.වචන ගණන් කිරීම. (4 marksලකුණු 4)
Show model answerආදර්ශ පිළිතුර පෙන්වන්න
5Explain mutable and immutable with examples.mutable සහ immutable. (2 marksලකුණු 2)
Show model answerආදර්ශ පිළිතුර පෙන්වන්න
🎮 Game🎮 ක්රීඩා
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බාගත කිරීම්
Resource Book Lesson Note Download Questions Syllabus Sinhala LMS Simulator Tool
