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

ตอบกระทู้

รูปแสดงอารมณ์
:icon_plusone: :like: :plusone: :gfb: :-D :) :( :-o 8O :? 8) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen: :angry: :baa: :biggrin:
รูปแสดงอารมณ์อื่นๆ

BBCode เปิด
[img] เปิด
[url] เปิด
[Smile icon] เปิด

กระทู้แนะนำ
   

มุมมองที่ขยายได้ กระทู้แนะนำ: ทำความรู้จักกับภาษา python (8) : ตัวแปรชนิด Dictionary (ดิกชันนารี)

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

โดย jirawoot » 19/06/2019 3:18 pm

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

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 723 times

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

โดย chatee supasand » 07/06/2019 3:56 pm

ตามมาจากวีดีโอใน ยูทูปครับ อธิบายได้เข้าใจมากครับ

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

โดย rangsan » 03/05/2018 3:44 pm

ตัวแปรชนิด 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 1617 times
ศึกษาจาก : https://www.youtube.com/watch?v=hSQ4gce ... lzdKrpxsMM

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

โดย Patcharanan.0399 » 19/04/2018 3:36 pm

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

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 1629 times
ศึกษาจาก https://youtu.be/hSQ4gceSMsU

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

โดย Jom07 » 23/01/2018 6:00 pm

ตัวแปรชนิด 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

ตัวแปรชนิด Dictionary

โดย Four » 18/01/2018 5:52 pm

บทที่ 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 (ดิกชันนารี)

โดย dawthana » 30/12/2016 9:45 am

สามารถศึกษาข้อมูลเพิ่มเติมได้ที่ https://www.mindphp.com/vdo-tutorial-pyt ... onary.html

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

โดย mindphp » 28/12/2016 9:22 pm

vdo สอน พร้อม download ไฟล์ตัวอย่าง
https://www.mindphp.com/vdo-tutorial-pyt ... onary.html

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

โดย dawthana » 28/12/2016 5:24 pm

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

ข้างบน