หน้า 1 จากทั้งหมด 1

ทำความรู้จักกับภาษา python (8) : ตัวแปรชนิด Dictionary (ดิกชันนารี)

โพสต์แล้ว: 28/12/2016 5:24 pm
โดย dawthana
ตัวแปรชนิด Dictionary (ดิกชันนารี)
ตัวแปรชนิด Dictionary ของ #Python จะคล้ายกับตัวแปร Array (อาร์เรย์) ในภาษา PHP (พีเอชพี) โดยจะต้องมี Key (คีย์) และ Value(แวลู่) คู่กันเสมอ
การกำหนดตัวแปร Dictionary
-การกำหนดค่าให้กับตัวแปร Dictionary จะต้องอยู่ภายใต้เครื่องหมาย {...}
ตัวอย่างการแสดงผล ซึ่งการแสดงผลจะเรียงลำดับ index จากค่าน้อยไปหามาก
dic1.png
dic1.png (37.39 KiB) Viewed 1773 times
การเพิ่มค่าให้กับตัวแปร Dictionary
ตัวอย่างการแสดงผลการเพิ่มค่าตัวแปร
dic3.png
dic3.png (32.94 KiB) Viewed 1773 times
การลบค่าในตัวแปร dictionary
ตัวอย่างการแสดงผลการลบค่าตัวแปร
dic4.png
dic4.png (31.72 KiB) Viewed 1773 times
ความแตกต่างระหว่าง List , Tuple และ Dictionary
List (ลิส)
Key Auto(คีย์ออโต้) , Update(อัพเดท)ได้ และ Delete(ดีลลีท)ได้
Tuple (ทูเปิล)
Key Auto , Updateไม่ได้ และ Deleteไม่ได้
Dictionary
กำหนด Key เอง , Updateได้ และ Deleteได้

ศึกษาข้อมูลจาก https://www.youtube.com/watch?v=hSQ4gce ... MM&index=8

Re: ทำความรู้จักกับภาษา python (8) : ตัวแปรชนิด Dictionary (ดิกชันนารี)

โพสต์แล้ว: 28/12/2016 9:22 pm
โดย mindphp
vdo สอน พร้อม download ไฟล์ตัวอย่าง
https://www.mindphp.com/vdo-tutorial-pyt ... onary.html

Re: ทำความรู้จักกับภาษา python (8) : ตัวแปรชนิด Dictionary (ดิกชันนารี)

โพสต์แล้ว: 30/12/2016 9:45 am
โดย dawthana
สามารถศึกษาข้อมูลเพิ่มเติมได้ที่ https://www.mindphp.com/vdo-tutorial-pyt ... onary.html

Re: ทำความรู้จักกับภาษา python (8) : ตัวแปรชนิด Dictionary (ดิกชันนารี)

โพสต์แล้ว: 02/02/2017 6:35 pm
โดย Dive Demo
เข้าใจครับ

ตัวแปรชนิด Dictionary

โพสต์แล้ว: 18/01/2018 5:52 pm
โดย Four
บทที่ 8 https://www.youtube.com/watch?v=hSQ4gce ... lzdKrpxsMM

Dictionary การกำหนดค่าจะใช้ {} สามารถเพิ่มลบข้อมูลได้ และต้องมี Key และ value คู่กัน

โค้ด: เลือกทั้งหมด

list = ["a", "b", "c", "d"]
tuple = (1, 2, 3, 4)
dic = {1 : "Mindphp", 2 : "test", 3 : 4}

del (dic[3],list[1])

dic[3] = 20

print (list)
print (tuple)
print (dic)
ผลรัน

รูปภาพ

Re: ทำความรู้จักกับภาษา python (8) : ตัวแปรชนิด Dictionary (ดิกชันนารี)

โพสต์แล้ว: 23/01/2018 6:00 pm
โดย Jom07
ตัวแปรชนิด Dictionary (ดิกชันนารี)

โค้ด: เลือกทั้งหมด

var_dict = {"name" : "Boy", "Age" : 8, "Class" : "Python" }

var_dict["name"] = "Girl"
var_dict["school"] = "Mindphp"

print (var_dict["name"])
print (var_dict["school"])
ผลรัน

รูปภาพ

ศึกษาข้อมูลจาก : https://www.youtube.com/watch?v=hSQ4gce ... MM&index=8

Re: ทำความรู้จักกับภาษา python (8) : ตัวแปรชนิด Dictionary (ดิกชันนารี)

โพสต์แล้ว: 19/04/2018 3:36 pm
โดย Patcharanan.0399

โค้ด: เลือกทั้งหมด

dict1 = {}
dict1["one"] = "This is one"
dict1[2] = "This is two"

dict2 = {1:"This is One", 2:"This is Two", "Three":3}

print (dict1)
print (dict2)
ผลการรัน
ผลลัพธ์การแสดงผลตัวแปร Dictionary.jpg
ผลลัพธ์การแสดงผลตัวแปร Dictionary.jpg (6.73 KiB) Viewed 1628 times
ศึกษาจาก https://youtu.be/hSQ4gceSMsU

Re: ทำความรู้จักกับภาษา python (8) : ตัวแปรชนิด Dictionary (ดิกชันนารี)

โพสต์แล้ว: 03/05/2018 3:44 pm
โดย rangsan
ตัวแปรชนิด Dictionary (ดิกชันนารี)

โค้ด: เลือกทั้งหมด

ex_dic = {"Name" : "Rangsan,Umnang" , "Lastname" : "Mungklang,Kitipakdee", "Age" : "22,27" }

ex_dic["Lastname"] = "Mung,Kit"
ex_dic["Age"] = 30,22

print (ex_dic)

ผลการรันโค้ด
Dictionary.png
Dictionary.png (20.05 KiB) Viewed 1616 times
ศึกษาจาก : https://www.youtube.com/watch?v=hSQ4gce ... lzdKrpxsMM

Re: ทำความรู้จักกับภาษา python (8) : ตัวแปรชนิด Dictionary (ดิกชันนารี)

โพสต์แล้ว: 07/06/2019 3:56 pm
โดย chatee supasand
ตามมาจากวีดีโอใน ยูทูปครับ อธิบายได้เข้าใจมากครับ

Re: ทำความรู้จักกับภาษา python (8) : ตัวแปรชนิด Dictionary (ดิกชันนารี)

โพสต์แล้ว: 19/06/2019 3:18 pm
โดย jirawoot

โค้ด: เลือกทั้งหมด

dict1={}
dict1['one']='hello'
dict1[2]= 'hello2'


dict2={1:'one', 2:'twe', 'tree':3}

print(dict1)
print(dict2)
Selection_0213129.png
Selection_0213129.png (6.56 KiB) Viewed 722 times