02 Python
เรียน Python ทีละขั้น ตั้งแต่ print() และตัวแปร ไปจนถึงโครงสร้างควบคุม ไฟล์ และโปรแกรมตัวอย่าง
An overview of Python and how to use this site to learn and practise ภาพรวมภาษา 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
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
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) หลังเครื่องหมาย : แทน { }
|
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
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 วิเคราะห์ข้อมูลและทำงานอัตโนมัติ
if, match, try, for and while — the tools that give a program its logic.if match try for และ while เครื่องมือที่ทำให้โปรแกรมมี logicTake 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.
ควรเรียนตามลำดับนี้ เพราะแต่ละบทใช้แนวคิดจากบทก่อนหน้า ลองทุกตัวอย่าง แก้โค้ด แล้วกดรันอีกครั้งก่อนทำแบบทดสอบ
เรียน Python ทีละขั้น ตั้งแต่ print() และตัวแปร ไปจนถึงโครงสร้างควบคุม ไฟล์ และโปรแกรมตัวอย่าง