ทำความรู้จักกับภาษา python (8) : ตัวแปรชนิด Dictionary (ดิกชันนารี)
Moderators: mindphp, ผู้ดูแลกระดาน
-
- PHP Super Hero Member
- Posts: 604
- Joined: 07/12/2016 10:55 am
ทำความรู้จักกับภาษา python (8) : ตัวแปรชนิด Dictionary (ดิกชันนารี)
ตัวแปรชนิด Dictionary (ดิกชันนารี)
ตัวแปรชนิด Dictionary ของ #Python จะคล้ายกับตัวแปร Array (อาร์เรย์) ในภาษา PHP (พีเอชพี) โดยจะต้องมี Key (คีย์) และ Value(แวลู่) คู่กันเสมอ
การกำหนดตัวแปร Dictionary
-การกำหนดค่าให้กับตัวแปร Dictionary จะต้องอยู่ภายใต้เครื่องหมาย {...}
ตัวอย่างการแสดงผล ซึ่งการแสดงผลจะเรียงลำดับ index จากค่าน้อยไปหามาก การเพิ่มค่าให้กับตัวแปร Dictionary
ตัวอย่างการแสดงผลการเพิ่มค่าตัวแปร การลบค่าในตัวแปร dictionary
ตัวอย่างการแสดงผลการลบค่าตัวแปร ความแตกต่างระหว่าง 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
ตัวแปรชนิด Dictionary ของ #Python จะคล้ายกับตัวแปร Array (อาร์เรย์) ในภาษา PHP (พีเอชพี) โดยจะต้องมี Key (คีย์) และ Value(แวลู่) คู่กันเสมอ
การกำหนดตัวแปร Dictionary
-การกำหนดค่าให้กับตัวแปร Dictionary จะต้องอยู่ภายใต้เครื่องหมาย {...}
ตัวอย่างการแสดงผล ซึ่งการแสดงผลจะเรียงลำดับ index จากค่าน้อยไปหามาก การเพิ่มค่าให้กับตัวแปร Dictionary
ตัวอย่างการแสดงผลการเพิ่มค่าตัวแปร การลบค่าในตัวแปร dictionary
ตัวอย่างการแสดงผลการลบค่าตัวแปร ความแตกต่างระหว่าง 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
- mindphp
- ผู้ดูแลระบบ MindPHP
- Posts: 26684
- Joined: 22/09/2008 6:18 pm
- Contact:
Re: ทำความรู้จักกับภาษา python (8) : ตัวแปรชนิด Dictionary (ดิกชันนารี)
vdo สอน พร้อม download ไฟล์ตัวอย่าง
https://www.mindphp.com/vdo-tutorial-pyt ... onary.html
https://www.mindphp.com/vdo-tutorial-pyt ... onary.html
ติดตาม VDO: http://www.youtube.com/c/MindphpVideoman
ติดตาม FB: https://www.facebook.com/pages/MindphpC ... 9517401606
หมวดแชร์ความรู้: https://www.mindphp.com/forums/viewforum.php?f=29
รับอบรม และพัฒนาระบบ: https://www.mindphp.com/forums/viewtopic.php?f=6&t=2042
ติดตาม FB: https://www.facebook.com/pages/MindphpC ... 9517401606
หมวดแชร์ความรู้: https://www.mindphp.com/forums/viewforum.php?f=29
รับอบรม และพัฒนาระบบ: https://www.mindphp.com/forums/viewtopic.php?f=6&t=2042
-
- PHP Super Hero Member
- Posts: 604
- Joined: 07/12/2016 10:55 am
Re: ทำความรู้จักกับภาษา python (8) : ตัวแปรชนิด Dictionary (ดิกชันนารี)
สามารถศึกษาข้อมูลเพิ่มเติมได้ที่ https://www.mindphp.com/vdo-tutorial-pyt ... onary.html
-
- PHP Sr. Member
- Posts: 84
- Joined: 01/02/2017 11:10 am
-
- PHP Super Hero Member
- Posts: 813
- Joined: 08/01/2018 9:55 am
ตัวแปรชนิด Dictionary
บทที่ 8 https://www.youtube.com/watch?v=hSQ4gce ... lzdKrpxsMM
Dictionary การกำหนดค่าจะใช้ {} สามารถเพิ่มลบข้อมูลได้ และต้องมี Key และ value คู่กัน
ผลรัน

Dictionary การกำหนดค่าจะใช้ {} สามารถเพิ่มลบข้อมูลได้ และต้องมี Key และ value คู่กัน
Code: Select all
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)
I am slow walker, but I never walk back. (Abraham Lincoln)
- Jom07
- PHP Super Hero Member
- Posts: 514
- Joined: 08/01/2018 9:56 am
Re: ทำความรู้จักกับภาษา python (8) : ตัวแปรชนิด Dictionary (ดิกชันนารี)
ตัวแปรชนิด Dictionary (ดิกชันนารี)
ผลรัน

ศึกษาข้อมูลจาก : https://www.youtube.com/watch?v=hSQ4gce ... MM&index=8
Code: Select all
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

-
- PHP Hero Member
- Posts: 114
- Joined: 09/04/2018 10:04 am
Re: ทำความรู้จักกับภาษา python (8) : ตัวแปรชนิด Dictionary (ดิกชันนารี)
Code: Select all
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)
-
- PHP Hero Member
- Posts: 199
- Joined: 30/04/2018 9:44 am
Re: ทำความรู้จักกับภาษา python (8) : ตัวแปรชนิด Dictionary (ดิกชันนารี)
ตัวแปรชนิด Dictionary (ดิกชันนารี)
ผลการรันโค้ด
ศึกษาจาก : https://www.youtube.com/watch?v=hSQ4gce ... lzdKrpxsMM
Code: Select all
ex_dic = {"Name" : "Rangsan,Umnang" , "Lastname" : "Mungklang,Kitipakdee", "Age" : "22,27" }
ex_dic["Lastname"] = "Mung,Kit"
ex_dic["Age"] = 30,22
print (ex_dic)
ผลการรันโค้ด
ศึกษาจาก : https://www.youtube.com/watch?v=hSQ4gce ... lzdKrpxsMM
It’s never too late to start again.
-
- Similar Topics
- Replies
- Views
- Last post
-
-
ตัวแปรชนิด Dictionary (ดิกชันนารี่) ใน Python (ไพทอน)
by md040 » 30/12/2016 11:04 am » in Python Knowledge - 1 Replies
- 259 Views
-
Last post by md040
30/12/2016 11:05 am
-
-
-
ทำความรู้จักกับภาษา python (6) : ตัวแปรชนิด List (ลิส)
by dawthana » 28/12/2016 2:25 pm » in Python Knowledge - 7 Replies
- 807 Views
-
Last post by jirawoot
19/06/2019 2:43 pm
-
-
-
ทำความรู้จักกับภาษา python (7) : ตัวแปรชนิด Tuple(ทูเปิล)
by dawthana » 28/12/2016 3:38 pm » in Python Knowledge - 7 Replies
- 719 Views
-
Last post by jirawoot
19/06/2019 3:02 pm
-
-
- 1 Replies
- 2563 Views
-
Last post by mindphp
25/09/2019 9:09 pm
-
-
ทำความรู้จักกับภาษา python (23) : การใช้ from...import (ฟอร์ม...อิมพอร์ต) ในภาษา python (ไพทอน)
by dawthana » 12/01/2017 3:24 pm » in Python Knowledge - 9 Replies
- 2498 Views
-
Last post by jirawoot
21/06/2019 10:07 am
-
Who is online
Users browsing this forum: No registered users and 21 guests