ทำความรู้จักกับภาษา python (8) : ตัวแปรชนิด Dictionary (ดิกชันนารี)
Moderator: mindphp, ผู้ดูแลกระดาน
-
- PHP Super Hero Member
- โพสต์: 604
- ลงทะเบียนเมื่อ: 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
- โพสต์: 41378
- ลงทะเบียนเมื่อ: 22/09/2008 6:18 pm
- ติดต่อ:
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
- โพสต์: 604
- ลงทะเบียนเมื่อ: 07/12/2016 10:55 am
Re: ทำความรู้จักกับภาษา python (8) : ตัวแปรชนิด Dictionary (ดิกชันนารี)
สามารถศึกษาข้อมูลเพิ่มเติมได้ที่ https://www.mindphp.com/vdo-tutorial-pyt ... onary.html
-
- PHP Sr. Member
- โพสต์: 84
- ลงทะเบียนเมื่อ: 01/02/2017 11:10 am
-
- PHP Super Hero Member
- โพสต์: 813
- ลงทะเบียนเมื่อ: 08/01/2018 9:55 am
ตัวแปรชนิด Dictionary
บทที่ 8 https://www.youtube.com/watch?v=hSQ4gce ... lzdKrpxsMM
Dictionary การกำหนดค่าจะใช้ {} สามารถเพิ่มลบข้อมูลได้ และต้องมี Key และ value คู่กัน
ผลรัน
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)
I am slow walker, but I never walk back. (Abraham Lincoln)
- Jom07
- PHP Super Hero Member
- โพสต์: 514
- ลงทะเบียนเมื่อ: 08/01/2018 9:56 am
Re: ทำความรู้จักกับภาษา python (8) : ตัวแปรชนิด Dictionary (ดิกชันนารี)
ตัวแปรชนิด Dictionary (ดิกชันนารี)
ผลรัน
ศึกษาข้อมูลจาก : https://www.youtube.com/watch?v=hSQ4gce ... MM&index=8
โค้ด: เลือกทั้งหมด
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
- โพสต์: 114
- ลงทะเบียนเมื่อ: 09/04/2018 10:04 am
Re: ทำความรู้จักกับภาษา python (8) : ตัวแปรชนิด Dictionary (ดิกชันนารี)
โค้ด: เลือกทั้งหมด
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
- โพสต์: 199
- ลงทะเบียนเมื่อ: 30/04/2018 9:44 am
Re: ทำความรู้จักกับภาษา python (8) : ตัวแปรชนิด Dictionary (ดิกชันนารี)
ตัวแปรชนิด Dictionary (ดิกชันนารี)
ผลการรันโค้ด
ศึกษาจาก : https://www.youtube.com/watch?v=hSQ4gce ... lzdKrpxsMM
โค้ด: เลือกทั้งหมด
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.
- chatee supasand
- PHP VIP Members
- โพสต์: 1666
- ลงทะเบียนเมื่อ: 04/06/2019 10:06 am
Re: ทำความรู้จักกับภาษา python (8) : ตัวแปรชนิด Dictionary (ดิกชันนารี)
ตามมาจากวีดีโอใน ยูทูปครับ อธิบายได้เข้าใจมากครับ
- jirawoot
- PHP VIP Members
- โพสต์: 3129
- ลงทะเบียนเมื่อ: 17/06/2019 10:30 am
Re: ทำความรู้จักกับภาษา python (8) : ตัวแปรชนิด Dictionary (ดิกชันนารี)
โค้ด: เลือกทั้งหมด
dict1={}
dict1['one']='hello'
dict1[2]= 'hello2'
dict2={1:'one', 2:'twe', 'tree':3}
print(dict1)
print(dict2)
-
- Similar Topics
- ตอบกลับ
- แสดง
- โพสต์ล่าสุด
-
-
โพสต์ใหม่ การใชังานตัวแปร dictionary ใน python
โดย ธวัชชัย แสนหาญ » 17/11/2018 6:19 pm » ใน Share Knowledge - 0 ตอบกลับ
- 1578 แสดง
-
โพสต์ล่าสุด โดย ธวัชชัย แสนหาญ
17/11/2018 6:19 pm
-
-
-
โพสต์ใหม่ ตัวแปรชนิด Dictionary (ดิกชันนารี่) ใน Python (ไพทอน)
โดย md040 » 30/12/2016 11:04 am » ใน Python Knowledge - 1 ตอบกลับ
- 455 แสดง
-
โพสต์ล่าสุด โดย md040
30/12/2016 11:05 am
-
-
-
โพสต์ใหม่ การใช้งาน Built in Dictionary ในภาษา python
โดย Four » 26/01/2018 4:49 pm » ใน Python Knowledge - 2 ตอบกลับ
- 1349 แสดง
-
โพสต์ล่าสุด โดย jirawoot
24/06/2019 3:08 pm
-
-
-
โพสต์ใหม่ ตัวแปร Dictionary ในภาษา python คืออะไร
โดย jirawoot » 25/06/2019 11:15 am » ใน Python Knowledge - 0 ตอบกลับ
- 1899 แสดง
-
โพสต์ล่าสุด โดย jirawoot
25/06/2019 11:15 am
-
ผู้ใช้งานขณะนี้
สมาชิกกำลังดูบอร์ดนี้: ไม่มีสมาชิกใหม่ และบุคลทั่วไป 85