

การเขียนโปรแกรมไพทอน
Presentation
•
Computers
•
7th - 12th Grade
•
Practice Problem
•
Hard
ครูวีรวัฒน์ ศักดิ์เพชรพลอย
Used 131+ times
FREE Resource
11 Slides • 10 Questions
1
Python List & Dict

2
List (ลิสต์)
ใช้เก็บข้อมูลจำนวนมากได้
ใช้ตัวเลขตำแหน่ง (index) ในการระบุตำแหน่ง
ตำแหน่งแรกของลิสต์คือ 0
สามารถเก็บได้ทั้ง ตัวเลข ตัวอักษร ค่าความจริง ลิสต์ และ ดิกต์
ใช้กฏการกำหนดชื่อเหมือนตัวแปรอื่น
ใช้เครื่องหมาย [ ] ในการสร้างลิสต์
3
ตัวอย่างการใช้ List
Code >>
name = ['Penny','Ellie','Koby','Olive','Ran','Andy']
print('คนที่ 1 คือ ',name[0])
print('คนที่ 3 คือ ',name[2])
print('คนที่ 5 คือ ',name[4])
Output >>
คนที่ 1 คือ Penny
คนที่ 3 คือ Koby
คนที่ 5 คือ Ran
4
Multiple Choice
name = ['Penny','Ellie','Koby','Olive','Ran','Andy']
คำถาม ถ้าต้องการให้โปรแกรมแสดงผลว่า Ran จะต้องใช้คำสั่งในข้อใด
print(5)
print(4)
print(name[5])
print(name[4])
5
Dict (ดิกต์)
ใช้เก็บข้อมูลจำนวนมากได้
ใช้ key ในการระบุตำแหน่ง
สามารถแทน key เป็น ตัวเลข ตัวอักษร ค่าความจริง ได้
สามารถเก็บได้ทั้ง ตัวเลข ตัวอักษร ค่าความจริง ลิสต์ และ ดิกต์
ใช้กฏการกำหนดชื่อเหมือนตัวแปรอื่น
ใช้เครื่องหมาย { } ในการสร้างดิกต์
6
ตัวอย่างการใช้ Dict
Code >>
student1 = {'id' : 9 , 'name' : 'Misty Lake'}
student2 = {'id' : 8 , 'name' : 'Scarlet Devil'}
print('รหัสนักเรียน', student1['id'], ' ชื่อ ', student9['name'])
print('รหัสนักเรียน', student2['id'], ' ชื่อ ', student8['name'])
Output >>
รหัสนักเรียน 9 ชื่อ Misty Lake
รหัสนักเรียน 8 ชื่อ Scarlet Devil
7
Multiple Choice
ถ้านักเรียนต้องการสร้าง Dict นักเรียนควรใช้สัญลักษณ์ใด
[ ]
( )
{ }
" "
8
Multiple Choice
ข้อใดต่อไปนี้ไม่สามารถใช้เป็น key ของ dict ได้
"Bob"
20
[20]
False
9
ตัวอย่างการใช้ List & Dict
Code >>
student = []
student.append( {'id' : 9 , 'name' : 'Misty Lake'} )
student.append( {'id' : 8 , 'name' : 'Scarlet Devil'} )
print('รหัสนักเรียน', student[0]['id'], ' ชื่อ ', student[0]['name'])
print('รหัสนักเรียน', student[1]['id'], ' ชื่อ ', student[1]['name'])
Output >>
รหัสนักเรียน 9 ชื่อ Misty Lake
รหัสนักเรียน 8 ชื่อ Scarlet Devil
10
Multiple Choice
snack = [{'id':1,'name':Lays},{'id':2,'name':Kitkat},{'id':3,'name':Pocky}]
ในลิสต์สินค้ามีขนมอยู่ 3 ชนิด ถ้าต้องการสั่ง Kitkat จะต้องสั่งสินค้าลำดับที่เท่าไร
0
1
2
11
Multiple Choice
snack = [{'id':1,'name':Lays},{'id':2,'name':Kitkat},{'id':3,'name':Pocky}]
จากข้อที่แล้วถ้าอยากได้ ชื่อสินค้า จะต้องเขียนโค๊ดตามข้อใด
snake[1]{'name'}
snack[1]['name']
snack[2]{'name'}
snack[2]{'name'}
12
การใช้ append & sort
Code >>
number = []
number.append(90)
number.append(65)
number.append(70)
number.sort()
print(number)
Output >>
[65,70,90]
13
การกำหนดค่าหลายตัวแปรโดยใช้ List
Code >>
number = []
number.append(90)
number.append(65)
number.append(70)
x,y,z = number
print('x = ',x,' y = ',y,' z = ',z)
Output >>
x = 90 y = 65 z = 70
14
การใช้ pop
Code >>
number = [60,70,90,100]
number.pop(2)
x,y,z = number
print('x = ',x,' y = ',y,' z = ',z)
Output >>
x = 65 y = 70 z = 100
15
การใช้ pop
Code >>
number = [60,70,90,100]
number.pop(2)
x,y,z = number
print(number.pop(2))
print(number)
Output >>
100
[60, 70]
16
การใช้ insert
Code >>
number = [60,90]
number.insert(1,70)
x,y,z = number
print(number)
Output >>
[60, 70 ,90]
17
Multiple Choice
2 + 3 + 5 x 0 + 5 x 2 + 10 x 0 = ?
5
10
15
0
18
Multiple Select
คำสั่งใดเป็นคำสั่งสำหรับเพิ่มค่าใน list (ตอบได้หลายตัวเลือก)
append
pop
insert
sort
19
Fill in the Blanks
Type answer...
20
Multiple Select
li = []
li.append(1,"Hello")
print("Hi")
print(li[1])
จากโค๊ดจะเกิด error บรรทัดใดบ้าง (เลือกตอบได้หลายบรรทัด)
1
2
3
4
ไม่มี Error
21
Multiple Choice
วันนี้เป็นวัน
ปีใหม่
สงกรานต์
พุธ
พุทธ
Python List & Dict

Show answer
Auto Play
Slide 1 / 21
SLIDE
Similar Resources on Wayground
13 questions
Basic Number Properties
Presentation
•
8th - 12th Grade
20 questions
Algorithms and Programs- Control Structures
Presentation
•
8th - 11th Grade
13 questions
Database objects - queries and forms
Presentation
•
7th - 11th Grade
19 questions
Los numeros en español.
Presentation
•
6th Grade - University
19 questions
Central Idea
Presentation
•
KG
15 questions
Python funkcja def()
Presentation
•
7th - 12th Grade
13 questions
Python Basics 1
Presentation
•
8th - 12th Grade
18 questions
O → UE Stem Changers
Presentation
•
6th - 12th Grade
Popular Resources on Wayground
10 questions
GPA Lesson
Presentation
•
9th - 12th Grade
7 questions
Albert Einstein
Quiz
•
3rd Grade
31 questions
Bridge A Review
Quiz
•
3rd Grade
6 questions
Blue Sue and Red Ruth
Quiz
•
3rd Grade
8 questions
(Day12 HW) Inverse Trig Ratios
Quiz
•
9th Grade
20 questions
Summer Geometry QUIZ (Week3)
Quiz
•
9th Grade
16 questions
Theme Practice
Quiz
•
7th Grade
20 questions
Taxes
Quiz
•
9th - 12th Grade
Discover more resources for Computers
10 questions
GPA Lesson
Presentation
•
9th - 12th Grade
8 questions
(Day12 HW) Inverse Trig Ratios
Quiz
•
9th Grade
20 questions
Summer Geometry QUIZ (Week3)
Quiz
•
9th Grade
16 questions
Theme Practice
Quiz
•
7th Grade
20 questions
Taxes
Quiz
•
9th - 12th Grade
16 questions
Warm Up: Basics of Geometry
Quiz
•
9th Grade
16 questions
Translations and Reflections
Quiz
•
9th - 10th Grade
17 questions
High School Survival Guide
Presentation
•
9th - 12th Grade