Python Lists

Python เบื้องต้น

Hugo Bowne-Anderson

Data Scientist at DataCamp

ชนิดข้อมูลใน Python

  • float - จำนวนจริง

  • int - จำนวนเต็ม

  • str - สตริง, ข้อความ

  • bool - True, False

height = 1.73
tall = True
  • แต่ละตัวแปรเก็บค่าได้เพียงค่าเดียว
Python เบื้องต้น

ปัญหา

  • Data Science: ข้อมูลมีจำนวนมาก

  • ความสูงของสมาชิกทุกคนในครอบครัว

height1 = 1.73
height2 = 1.68
height3 = 1.71
height4 = 1.89
  • ไม่สะดวก
Python เบื้องต้น

Python List

  • [a, b, c]
[1.73, 1.68, 1.71, 1.89]
[1.73, 1.68, 1.71, 1.89]
fam = [1.73, 1.68, 1.71, 1.89]
fam
[1.73, 1.68, 1.71, 1.89]
  • ตั้งชื่อให้กลุ่มของค่า

  • เก็บข้อมูลได้ทุกชนิด

  • เก็บข้อมูลต่างชนิดกันได้

Python เบื้องต้น

Python List

  • [a, b, c]
fam = ["liz", 1.73, "emma", 1.68, "mom", 1.71, "dad", 1.89]

fam
['liz', 1.73, 'emma', 1.68, 'mom', 1.71, 'dad', 1.89]
fam2 = [["liz", 1.73],
        ["emma", 1.68],
        ["mom", 1.71],
        ["dad", 1.89]]

fam2
[['liz', 1.73], ['emma', 1.68], ['mom', 1.71], ['dad', 1.89]]
Python เบื้องต้น

ชนิด list

type(fam)
list
type(fam2)
list
  • ฟังก์ชันการทำงานเฉพาะ

  • พฤติกรรมเฉพาะ

Python เบื้องต้น

มาฝึกกันเถอะ!

Python เบื้องต้น

Preparing Video For Download...