Python programming การเขียนโปรแกรมด้วย Python

An overview of Python and how to use this site to learn and practise ภาพรวมภาษา Python และวิธีใช้เว็บไซต์นี้สำหรับเรียนรู้และฝึกฝน

What is Python? Python คืออะไร

Python is a high-level programming language designed to be easy to read and write. It was created by Guido van Rossum and first released around 1991. Its popularity has kept growing, which has driven rapid library development — especially libraries for AI/ML — so Python is now a common choice for teaching basic programming.

Python เป็นภาษาโปรแกรมระดับสูงที่เน้นให้อ่านและเขียนง่าย ออกแบบโดย Guido van Rossum และเริ่มเผยแพร่ใช้งานราวปี ค.ศ. 1991 ในปี 2020 ภาษานี้มีความนิยมมากขึ้นเรื่อยๆ ทำให้มีการพัฒนา Library ไปได้รวดเร็ว โดยเฉพาะ Library สำหรับงานด้าน AI/ML ทำให้งานสอนเขียน Programming พื้นฐานนิยมใช้ภาษา Python

Real-world uses today ตัวอย่างการใช้งานจริงในปัจจุบัน

  • Data analysis, statistics, and data visualization
  • Artificial intelligence and machine learning (AI / ML)
  • Automation scripts — e.g. file handling, repetitive data processing
  • Talking to sensors, IoT devices, and embedded systems through related libraries
  • Science, computation, and rapid prototyping of programs
  • วิเคราะห์ข้อมูล สถิติ และการแสดงผลข้อมูล (data analysis / visualization)
  • ปัญญาประดิษฐ์และการเรียนรู้ของเครื่อง (AI / machine learning)
  • เขียนสคริปต์อัตโนมัติ (automation) เช่น จัดการไฟล์ ประมวลผลข้อมูลซ้ำๆ
  • เชื่อมต่อเซนเซอร์ อุปกรณ์ IoT และระบบฝังตัวผ่านไลบรารีที่เกี่ยวข้อง
  • งานวิทยาศาสตร์ การคำนวณ และการสร้างต้นแบบโปรแกรมอย่างรวดเร็ว

Why learn Python? ทำไมต้องเรียนรู้ภาษา Python?

A comparison of the programming style and best-fit tasks of LabVIEW, C in the Arduino IDE, and Python.

เปรียบเทียบสไตล์การเขียนโปรแกรมและงานที่เหมาะของ LabVIEW, C ใน Arduino IDE และ Python

Topicหัวข้อ LabVIEW C (Arduino IDE) Python
Writing styleสไตล์การเขียน Graphical / dataflow — drag-and-drop blocks and wires แบบภาพ (graphical / dataflow) ลากวางบล็อกและสายสัญญาณ Text, with semicolons and braces {} to mark blocks ข้อความ (text) มี semicolon และวงเล็บปีกกา {} กำหนดบล็อก Text, using indentation instead of {} — easy to read ข้อความ (text) เน้นย่อหน้า (indentation) แทน {} อ่านง่าย
Best-fit tasksงานที่เหมาะ Lab measurement & control, test systems, instruments and industrial systems วัดคุมในแล็บ ระบบทดสอบ เครื่องมือวัดและระบบอุตสาหกรรม Controlling microcontrollers, reading sensors, real-time hardware control ควบคุมไมโครคอนโทรลเลอร์ อ่านเซนเซอร์ สั่งงานฮาร์ดแวร์แบบเรียลไทม์ Learning to program, data analysis, automation, web, and AI/ML work เรียนรู้โปรแกรม วิเคราะห์ข้อมูล สคริปต์อัตโนมัติ เว็บ และงาน AI/ML

Most Python libraries are open source, so they develop quickly and cover a wider range than LabVIEW.

Library สำหรับ Python ส่วนใหญ่เป็น Open Source ทำให้มีการพัฒนา Library ไปได้รวดเร็วและมีความหลากหลายมากกว่า LabVIEW

Python syntax compared with C in Arduino Python Syntax เปรียบเทียบกับภาษา C in Arduino

Common differences when moving from C in the Arduino IDE to Python:

จุดที่มักต่างกันเมื่อย้ายจาก C ใน Arduino IDE มาเขียน Python:

Topicหัวข้อ C (Arduino IDE) Python
Ending a statement / new line การจบบรรทัด / ขึ้นบรรทัดใหม่ Usually ends a statement with ; มักปิดท้ายคำสั่งด้วย ; No ; needed — a new line ends the statement ไม่ต้องใส่ ; — ขึ้นบรรทัดใหม่คือจบคำสั่ง
Marking a code block การกำหนดขอบเขตบล็อกโค้ด Wraps the block in { }, e.g. while, for, if ใช้ { } ครอบบล็อก เช่น while, for, if Uses indentation after a : instead of { } ใช้ย่อหน้า (indentation) หลังเครื่องหมาย : แทน { }

How to use this site to learn and practise Python การใช้งานเว็บไซต์สำหรับเรียนรู้และฝึกฝนภาษา python

  1. Each chapter explains the key functions or statements it introduces.
  2. Code examples are shown with a Run button so you can see the output.
  3. The example boxes are editable, so you can practise writing code.
  1. แต่ละบทจะอธิบายฟังก์ชันหรือคำสั่งสำคัญที่เกี่ยวข้อง
  2. มีตัวอย่างโค้ดให้ดูและกด Run เพื่อดูผลลัพธ์
  3. มีส่วนให้ฝึกเขียนโค้ดในกล่องตัวอย่าง (แก้ไขได้)

Note: code on this site runs on a JavaScript simulator, not a real Python interpreter. To try real Python, use Google Colab.

หมายเหตุ: โค้ดที่รันบนเว็บไซต์นี้เป็นการจำลองด้วย JavaScript ไม่ใช่ตัวแปลภาษา Python จริง หากต้องการทดลอง Python จริง แนะนำใช้ Google Colab

Who it is for เหมาะกับใคร

Beginners who have finished 01 Basic or already know what a variable is, and engineers who work with LabVIEW or C on a microcontroller and want Python for data analysis and automation.

ผู้เริ่มต้นที่เรียน 01 Basic แล้วหรือรู้จักตัวแปรอยู่แล้ว และวิศวกรที่ใช้ LabVIEW หรือภาษา C กับไมโครคอนโทรลเลอร์ แล้วอยากใช้ Python วิเคราะห์ข้อมูลและทำงานอัตโนมัติ

Learning order ลำดับการเรียนรู้

  1. Lessons 01–08: the basics — printing, variables, input and output, booleans, numbers, strings, lists and dictionaries.
  2. 09 Control Structures: if, match, try, for and while — the tools that give a program its logic.
  3. 10 Data Files: reading and writing files.
  4. Example Programs: worked problems that combine everything above, each with a flowchart explanation and runnable code.
  1. บท 01–08: พื้นฐาน — การแสดงผล ตัวแปร การรับค่าและแสดงผล บูลีน ตัวเลข สตริง list และ dictionary
  2. 09 โครงสร้างควบคุม: if match try for และ while เครื่องมือที่ทำให้โปรแกรมมี logic
  3. 10 ไฟล์ข้อมูล: อ่านและเขียนไฟล์
  4. ตัวอย่างโปรแกรม: โจทย์ที่รวมทุกเรื่องข้างต้น พร้อมคำอธิบาย flowchart และโค้ดที่รันได้

Take them in this order, because each lesson uses ideas from the ones before it. Try every example, change the code, and run it again before you open the quiz.

ควรเรียนตามลำดับนี้ เพราะแต่ละบทใช้แนวคิดจากบทก่อนหน้า ลองทุกตัวอย่าง แก้โค้ด แล้วกดรันอีกครั้งก่อนทำแบบทดสอบ

02 Python

เรียน Python ทีละขั้น ตั้งแต่ print() และตัวแปร ไปจนถึงโครงสร้างควบคุม ไฟล์ และโปรแกรมตัวอย่าง