ยินดีต้อนรับ!

การเขียน Python Code ที่มีประสิทธิภาพ

Logan Thomas

Scientific Software Technical Trainer, Enthought

ภาพรวมของคอร์ส

  • โค้ดควรเป็นเครื่องมือสำหรับดึงข้อมูลเชิงลึก
    • ไม่ใช่สิ่งที่ทำให้ต้องรอผลลัพธ์นาน
  • ในคอร์สนี้จะได้เรียนรู้:
    • วิธีเขียนโค้ด Python ที่สะอาด รวดเร็ว และมีประสิทธิภาพ
    • วิธี profile โค้ดเพื่อหาจุดที่เป็น bottleneck
    • วิธีกำจัด bottleneck และรูปแบบการออกแบบที่ไม่ดี
การเขียน Python Code ที่มีประสิทธิภาพ

นิยามของ efficient

  • การเขียนโค้ด Python ที่ มีประสิทธิภาพ
    • ใช้เวลาน้อยที่สุด (runtime เร็ว)
    • ใช้ทรัพยากรน้อยที่สุด (memory footprint เล็ก)

alt="สมการแสดงนาฬิกาจับเวลาพร้อมลูกศรชี้ลงบวกกับแฟลชไดรฟ์พร้อมลูกศรชี้ลงเท่ากับคำว่า efficient"

การเขียน Python Code ที่มีประสิทธิภาพ

นิยามของ Pythonic

  • การเขียนโค้ด Python ที่มีประสิทธิภาพ
    • เน้นความอ่านง่าย
    • ใช้งานโครงสร้างของ Python ตามที่ออกแบบไว้ (กล่าวคือ Pythonic)

# Non-Pythonic
doubled_numbers = []

for i in range(len(numbers)):
    doubled_numbers.append(numbers[i] * 2)

# Pythonic doubled_numbers = [x * 2 for x in numbers]
การเขียน Python Code ที่มีประสิทธิภาพ

The Zen of Python โดย Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
...
การเขียน Python Code ที่มีประสิทธิภาพ

สิ่งที่ควรรู้มาก่อน

การเขียน Python Code ที่มีประสิทธิภาพ

มาเริ่มกันเลย!

การเขียน Python Code ที่มีประสิทธิภาพ

Preparing Video For Download...