Python Sinhalen | පයිතන් සිංහලෙන් #3 - Python Dictionary

ඔන්න අදත් අරන් ආවා අපේ Python පාඩම් මාලාවේ තුන් වෙනි කොටස. අද කතා කරන්නේ Python Dictionary ගැන. Dictionary එකක් කියන එක හැමෝම දන්නවනේ වෙන දේ. එහෙනම් අපි  අපේ වැඩේට බහිමු.
ආ.. කලින් පාඩම් බැලුවේ නැත්තම් ඒවා බලලා මේකට එන්න...
අපි මුලින්ම බලමු Dictionary එකක් පයිතන් වලින් නිරුපනය කරන්නේ කොහොමද කියලා.
ඒකට අපි භාවිත කරන්නේ සඟල වරහන් දෙකක්. { } 

Create Dictionary | Dictionary එකක් සෑදීම

උදා :-  dict = {'Name' : 'Amal' , 'Age' : 21, 'Class' : 'First'}

අපි දැන් ඉහත සාදාගත් Dictionary එකේ දත්ත කියවන ආකාරය බලමු.

print(dict['Name'])

'Name' වෙනුවට Age , Class  දීමෙන් ඊට අදාල දත්ත ලබා ගත හැක.

Updating Dictionary | යාවත්කාලින කිරීම

  • ඇති දත්තයක් වෙනස් කිරීම
                 dict['Age'] = 19
  • අලුතින් දත්තයක් එකතු කිරීම
                dict['Country'] = 'Sri Lanka'

Delete Dictionary Elements | මුලාංග මැකීම

  • තනි දත්තයක් මැකීම
                del dict['Age']          <--- ( 'Age' යන්න මැකී යයි)
  • සියලුම දත්ත මැකීම ( Empty )
                dict.clear()
  • Dictionary එකම මැකීම ( Delete )
                del dict

සැලකිය යුතුයි

Dictionary එකක එකම නමින් දත්ත කීපයක් ඇතුලත් කල විට අවසානයට ඇතුලත් කල දත්තය පමණක් Dictionary එක තුල ඉතිරි වේ

උදා :- dict2 = {'Name' : 'Amal' , 'Age' : 8 , 'School' : 'PQRS' , 'Age' : 12 }
ලෙස ඩික්ෂනරි එකක් සෑදු විට 'Age' නමින් දත්ත දෙකක් ඇති නිසා අවසානයේ ඇති දත්තය පමණක් ඩික්ෂනරි එක ට ඇතුලත් වේ. එනම්,
print(dict2['Age']);   මෙගින් ලැබෙන්නේ 12 පිළිතුරයි.

dictionary functions

SNFunction with Description
1
Compares elements of both dict.
2
Gives the total length of the dictionary. This would be equal to the number of items in the dictionary.
3
Produces a printable string representation of a dictionary
4
Returns the type of the passed variable. If passed variable is dictionary, then it would return a dictionary type.

dictionary methods


SNMethods with Description
1
Removes all elements of dictionary dict
2
Returns a shallow copy of dictionary dict
3
Create a new dictionary with keys from seq and values set to value.
4
For key key, returns value or default if key not in dictionary
5
Returns true if key in dictionary dictfalse otherwise
6
Returns a list of dict's (key, value) tuple pairs
7
Returns list of dictionary dict's keys
8
Similar to get(), but will set dict[key]=default if key is not already in dict
9
Adds dictionary dict2's key-values pairs to dict
10
Returns list of dictionary dict's values
ප:ලි:
dict ලෙස සාදා ඇති variable name එක සඳහා ඔබට කැමති නමක් යෙදිය හැක. එක Dictionary එකක් බවට පත් වෙන්නේ {} භාවිත කිරීමෙනි.

එහෙනම් මම අදට යනවා. මේක Share කරලා සප් එකක් දෙන්න.ඔයාලගේ අදහසුත් පහලින් දාගෙන යන්න. තවත් ලිපියකින් හමු වෙමු.


Facebook Page එකට like කරලා නැත්තම් like කරන්න - www.facebook.com/computer.sof
★Twitter හරහා Follow කරන්න - www.twitter.com/cosoblog
★Chat එකට සෙට් වෙන්නත් පුළුවන් ඔයාලගේ ප්‍රශ්න/ගැටලු සාකච්චා කරන්න - Chat Box
★අලුත් ලිපි නොමිලේම ඔබේ ජංගම දුරකථනයට ගෙන්වා ගැනීමට Follow cosoblog ලෙස Type කර 40404 ට Send කරන්න.
Python Sinhalen | පයිතන් සිංහලෙන් #3 - Python Dictionary Python Sinhalen | පයිතන් සිංහලෙන් #3 - Python Dictionary Reviewed by RDM Rajapakshe on 10:06:00 AM Rating: 5

No comments:

Powered by Blogger.