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

แชร์ความรู้ภาษา Python ไพทอน การเขียนโปรแกรมภาษาไพทอน

Moderator: mindphp, ผู้ดูแลกระดาน

dawthana
PHP Super Hero Member
PHP Super Hero Member
โพสต์: 604
ลงทะเบียนเมื่อ: 07/12/2016 10:55 am

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

โพสต์ที่ยังไม่ได้อ่าน โดย dawthana »

ตัวแปรชนิด Dictionary (ดิกชันนารี)
ตัวแปรชนิด Dictionary ของ #Python จะคล้ายกับตัวแปร Array (อาร์เรย์) ในภาษา PHP (พีเอชพี) โดยจะต้องมี Key (คีย์) และ Value(แวลู่) คู่กันเสมอ
การกำหนดตัวแปร Dictionary
-การกำหนดค่าให้กับตัวแปร Dictionary จะต้องอยู่ภายใต้เครื่องหมาย {...}
ตัวอย่างการแสดงผล ซึ่งการแสดงผลจะเรียงลำดับ index จากค่าน้อยไปหามาก
dic1.png
dic1.png (37.39 KiB) Viewed 1771 times
การเพิ่มค่าให้กับตัวแปร Dictionary
ตัวอย่างการแสดงผลการเพิ่มค่าตัวแปร
dic3.png
dic3.png (32.94 KiB) Viewed 1771 times
การลบค่าในตัวแปร dictionary
ตัวอย่างการแสดงผลการลบค่าตัวแปร
dic4.png
dic4.png (31.72 KiB) Viewed 1771 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
ภาพประจำตัวสมาชิก
mindphp
ผู้ดูแลระบบ MindPHP
ผู้ดูแลระบบ MindPHP
โพสต์: 41232
ลงทะเบียนเมื่อ: 22/09/2008 6:18 pm
ติดต่อ:

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

โพสต์ที่ยังไม่ได้อ่าน โดย mindphp »

vdo สอน พร้อม download ไฟล์ตัวอย่าง
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
dawthana
PHP Super Hero Member
PHP Super Hero Member
โพสต์: 604
ลงทะเบียนเมื่อ: 07/12/2016 10:55 am

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

โพสต์ที่ยังไม่ได้อ่าน โดย dawthana »

สามารถศึกษาข้อมูลเพิ่มเติมได้ที่ https://www.mindphp.com/vdo-tutorial-pyt ... onary.html
Four
PHP Super Hero Member
PHP Super Hero Member
โพสต์: 813
ลงทะเบียนเมื่อ: 08/01/2018 9:55 am

ตัวแปรชนิด Dictionary

โพสต์ที่ยังไม่ได้อ่าน โดย 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)
ผลรัน

รูปภาพ
I am slow walker, but I never walk back. (Abraham Lincoln)
ภาพประจำตัวสมาชิก
Jom07
PHP Super Hero Member
PHP Super Hero Member
โพสต์: 514
ลงทะเบียนเมื่อ: 08/01/2018 9:56 am

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

โพสต์ที่ยังไม่ได้อ่าน โดย 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
รูปภาพ
Patcharanan.0399
PHP Hero Member
PHP Hero Member
โพสต์: 114
ลงทะเบียนเมื่อ: 09/04/2018 10:04 am

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

โพสต์ที่ยังไม่ได้อ่าน โดย 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 1626 times
ศึกษาจาก https://youtu.be/hSQ4gceSMsU
rangsan
PHP Hero Member
PHP Hero Member
โพสต์: 199
ลงทะเบียนเมื่อ: 30/04/2018 9:44 am

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

โพสต์ที่ยังไม่ได้อ่าน โดย 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 1614 times
ศึกษาจาก : https://www.youtube.com/watch?v=hSQ4gce ... lzdKrpxsMM
It’s never too late to start again.
ภาพประจำตัวสมาชิก
chatee supasand
PHP VIP Members
PHP VIP Members
โพสต์: 1666
ลงทะเบียนเมื่อ: 04/06/2019 10:06 am

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

โพสต์ที่ยังไม่ได้อ่าน โดย chatee supasand »

ตามมาจากวีดีโอใน ยูทูปครับ อธิบายได้เข้าใจมากครับ
รูปภาพ
ภาพประจำตัวสมาชิก
jirawoot
PHP VIP Members
PHP VIP Members
โพสต์: 3129
ลงทะเบียนเมื่อ: 17/06/2019 10:30 am

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

โพสต์ที่ยังไม่ได้อ่าน โดย 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 720 times
ตอบกลับโพส
  • Similar Topics
    ตอบกลับ
    แสดง
    โพสต์ล่าสุด

ผู้ใช้งานขณะนี้

สมาชิกกำลังดูบอร์ดนี้: ไม่มีสมาชิกใหม่ และบุคลทั่วไป 77