เทคนิคง่ายๆ : ที่ทำให้โค้ด Python ของคุณเร็วขึ้น

Python Programming - เริ่มต้นเขียนโปรแกรมด้วย Python

Python Programming

เริ่มต้นเขียนโปรแกรมด้วยภาษา Python ที่ใช้งานง่ายและทรงพลัง

Python Programming

Python เป็นภาษาโปรแกรมมิ่งที่ได้รับความนิยมสูงสุดในปัจจุบัน ด้วยความเรียบง่ายในการเขียนโค้ด ความยืดหยุ่นในการใช้งาน และชุมชนนักพัฒนาที่แข็งแกร่ง Python เหมาะสำหรับทั้งผู้เริ่มต้นและมืออาชีพ ไม่ว่าจะเป็นการพัฒนาเว็บแอปพลิเคชัน การวิเคราะห์ข้อมูล Machine Learning, AI, IoT หรือ Automation บทความนี้จะพาคุณเริ่มต้นเรียนรู้ Python ตั้งแต่พื้นฐานจนถึงการสร้างโปรเจคจริง

Python คืออะไร?

Python เป็นภาษาโปรแกรมมิ่งระดับสูง (High-level Programming Language) ที่ถูกสร้างขึ้นโดย Guido van Rossum และเปิดตัวครั้งแรกในปี 1991 ชื่อ "Python" มาจากรายการตลกของ BBC ชื่อ "Monty Python's Flying Circus" ไม่ได้มาจากงูหลามอย่างที่หลายคนเข้าใจผิด

คุณสมบัติเด่นของ Python:

  • Syntax ที่อ่านง่าย - โค้ด Python อ่านเข้าใจได้เหมือนภาษาอังกฤษ ทำให้เรียนรู้ได้เร็วและเขียนโค้ดได้คล่องแคล่ว
  • Interpreted Language - ไม่ต้อง Compile ก่อนรัน สามารถเขียนและทดสอบโค้ดได้ทันที
  • Dynamically Typed - ไม่ต้องประกาศชนิดของตัวแปร Python จะกำหนดให้อัตโนมัติ
  • Object-Oriented - รองรับการเขียนโปรแกรมเชิงวัตถุ (OOP) อย่างสมบูรณ์
  • Cross-platform - ทำงานได้บนทุกระบบปฏิบัติการ Windows, macOS, Linux
  • Open Source - ใช้งานฟรีและมี Community ขนาดใหญ่

Python ใช้ทำอะไรได้บ้าง?

  • Web Development - Django, Flask, FastAPI
  • Data Science & Analytics - Pandas, NumPy, Matplotlib
  • Machine Learning & AI - TensorFlow, PyTorch, Scikit-learn
  • Automation & Scripting - ทำงานซ้ำๆ อัตโนมัติ
  • IoT & Hardware - MicroPython, CircuitPython สำหรับ ESP32, Raspberry Pi
  • Game Development - Pygame
  • Desktop Applications - Tkinter, PyQt

ทำไมต้องเรียน Python?

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

📊 สถิติที่น่าสนใจ:

  • Python เป็นภาษาที่ได้รับความนิยมอันดับ 1 ใน TIOBE Index
  • มีงานตำแหน่ง Python Developer มากกว่า 100,000 ตำแหน่งทั่วโลก
  • เงินเดือนเฉลี่ย Python Developer สูงกว่าภาษาอื่นๆ
  • บริษัทชั้นนำอย่าง Google, Netflix, Instagram, Spotify ใช้ Python

ข้อดีของการเรียน Python:

  • เรียนรู้ง่าย เหมาะกับผู้เริ่มต้น - Syntax ที่เรียบง่ายและอ่านง่าย ไม่ซับซ้อนเหมือนภาษาอื่น
  • ใช้งานได้หลากหลาย - จากการทำเว็บไซต์ไปจนถึง AI และ Machine Learning
  • Community ใหญ่ - มีคนช่วยเหลือมากมาย มี Tutorial และ Library เยอะ
  • ตลาดแรงงานต้องการสูง - มีงานเยอะและเงินเดือนดี
  • Library และ Framework มากมาย - มีเครื่องมือสำเร็จรูปให้ใช้งานมากมาย
  • เหมาะกับ Rapid Prototyping - สร้าง Prototype ได้เร็ว ทดสอบไอเดียได้ง่าย

Python vs ภาษาอื่น:

  • Python vs Java - Python เขียนโค้ดสั้นกว่า เรียนรู้ง่ายกว่า แต่ Java เร็วกว่าในบางกรณี
  • Python vs JavaScript - JavaScript ครองโลก Web Frontend, Python ครองโลก Data Science และ Backend
  • Python vs C++ - C++ เร็วกว่ามาก แต่ Python เขียนง่ายกว่าและพัฒนาเร็วกว่า

เริ่มต้นใช้งาน Python

การเริ่มต้นเขียน Python ทำได้ง่ายมาก เพียงแค่ติดตั้งและเขียนโค้ดบรรทัดแรกของคุณ

ขั้นตอนที่ 1: ติดตั้ง Python

  • Windows: ดาวน์โหลดจาก python.org และติดตั้ง อย่าลืมเช็ค "Add Python to PATH"
  • macOS: ติดตั้งผ่าน Homebrew: brew install python3
  • Linux: ส่วนใหญ่มี Python ติดตั้งมาแล้ว หรือติดตั้งผ่าน: sudo apt install python3

ขั้นตอนที่ 2: ตรวจสอบการติดตั้ง

เปิด Terminal หรือ Command Prompt แล้วพิมพ์:

python --version
หรือ
python3 --version

ถ้าเห็นเลขเวอร์ชัน เช่น Python 3.11.0 แสดงว่าติดตั้งสำเร็จแล้ว

ขั้นตอนที่ 3: เลือก Text Editor หรือ IDE

  • VS Code - แนะนำสำหรับผู้เริ่มต้น ฟรี มี Extension เยอะ
  • PyCharm - IDE เต็มรูปแบบสำหรับ Python มีทั้งแบบฟรีและแบบเสียเงิน
  • Jupyter Notebook - เหมาะสำหรับ Data Science และการเรียนรู้
  • Sublime Text - เบาและเร็ว
  • IDLE - มาพร้อมกับ Python เหมาะสำหรับผู้เริ่มต้น

ขั้นตอนที่ 4: เขียนโปรแกรมแรก

สร้างไฟล์ชื่อ hello.py แล้วเขียนโค้ด:

print("Hello, World!")
print("สวัสดี Python")

รันโปรแกรมด้วยคำสั่ง:

python hello.py

Python Interactive Mode:

คุณสามารถเขียนและทดสอบโค้ดทีละบรรทัดได้โดยพิมพ์ python หรือ python3 ใน Terminal

>>> print("Hello")
Hello
>>> 2 + 2
4
>>> name = "Python"
>>> print(f"I love {name}")
I love Python

Syntax พื้นฐาน

Python มี Syntax ที่เรียบง่ายและอ่านง่าย ต่างจากภาษาอื่นที่ใช้ปีกกา {} Python ใช้การเว้นวรรค (Indentation) ในการจัดโครงสร้างโค้ด

1. การเว้นวรรค (Indentation):

Python ใช้การเว้นวรรคเพื่อกำหนด Block ของโค้ด ต้องเว้นวรรคให้สม่ำเสมอ (แนะนำ 4 spaces)

if True:
    print("ถูกต้อง") # เว้น 4 spaces
    print("ต่อเนื่อง")
print("จบ if") # ไม่เว้นวรรค = นอก if block

2. Comments (คอมเมนต์):

# นี่คือคอมเมนต์บรรทัดเดียว

"""
นี่คือคอมเมนต์
หลายบรรทัด
"""

print("Hello") # คอมเมนต์ท้ายบรรทัด

3. ตัวแปร (Variables):

ไม่ต้องประกาศชนิดของตัวแปร Python จะกำหนดให้อัตโนมัติ

name = "John" # String
age = 25 # Integer
height = 175.5 # Float
is_student = True # Boolean

# ตั้งชื่อตัวแปรแบบ Snake Case
user_name = "Alice"
total_price = 1500

4. การพิมพ์ข้อความ (Print):

print("Hello, World!")
print("สวัสดี", "Python") # พิมพ์หลายค่า

# f-string (แนะนำ)
name = "Alice"
age = 25
print(f"ชื่อ: {name}, อายุ: {age}")

# format()
print("ชื่อ: {}, อายุ: {}".format(name, age))

# % formatting (แบบเก่า)
print("ชื่อ: %s, อายุ: %d" % (name, age))

5. การรับค่าจากผู้ใช้ (Input):

name = input("กรุณาใส่ชื่อ: ")
print(f"สวัสดี {name}")

# แปลงชนิดข้อมูล
age = int(input("อายุ: "))
height = float(input("ส่วนสูง (cm): "))

6. Operators (ตัวดำเนินการ):

# Arithmetic Operators
a = 10 + 5 # บวก = 15
b = 10 - 5 # ลบ = 5
c = 10 * 5 # คูณ = 50
d = 10 / 5 # หาร = 2.0
e = 10 // 3 # หารปัดเศษ = 3
f = 10 % 3 # หารเอาเศษ = 1
g = 2 ** 3 # ยกกำลัง = 8

# Comparison Operators
10 == 10 # เท่ากับ = True
10 != 5 # ไม่เท่ากับ = True
10 > 5 # มากกว่า = True
10 < 5 # น้อยกว่า = False
10 >= 10 # มากกว่าเท่ากับ = True
10 <= 5 # น้อยกว่าเท่ากับ = False

# Logical Operators
True and False # และ = False
True or False # หรือ = True
not True # ไม่ใช่ = False

ชนิดข้อมูล (Data Types)

Python มีชนิดข้อมูลพื้นฐานหลายแบบ แต่ละแบบมีการใช้งานที่แตกต่างกัน

1. Numbers (ตัวเลข):

# Integer (จำนวนเต็ม)
age = 25
year = 2024

# Float (ทศนิยม)
price = 99.99
pi = 3.14159

# Complex (จำนวนเชิงซ้อน)
z = 3 + 4j

2. String (ข้อความ):

# สร้าง String
name = "Alice"
message = 'Hello, World!'
multiline = """บรรทัดที่ 1
บรรทัดที่ 2
บรรทัดที่ 3"""

# String Operations
text = "Python"
print(text[0]) # P (ตัวแรก)
print(text[-1]) # n (ตัวสุดท้าย)
print(text[0:3]) # Pyt (ตัดข้อความ)
print(text.upper()) # PYTHON
print(text.lower()) # python
print(len(text)) # 6 (ความยาว)
print("Py" in text) # True (ตรวจสอบ)

# String Concatenation
first = "Hello"
last = "World"
full = first + " " + last # Hello World
repeat = "Ha" * 3 # HaHaHa

3. List (รายการ):

List เป็น Collection ที่เปลี่ยนแปลงได้ (Mutable) และเรียงลำดับ

# สร้าง List
fruits = ["apple", "banana", "orange"]
numbers = [1, 2, 3, 4, 5]
mixed = [1, "hello", 3.14, True]

# เข้าถึงข้อมูล
print(fruits[0]) # apple
print(fruits[-1]) # orange

# แก้ไขข้อมูล
fruits[1] = "mango"

# เพิ่มข้อมูล
fruits.append("grape") # เพิ่มท้ายสุด
fruits.insert(0, "kiwi") # เพิ่มตำแหน่งที่ 0

# ลบข้อมูล
fruits.remove("apple") # ลบตามค่า
fruits.pop() # ลบตัวสุดท้าย
fruits.pop(0) # ลบตำแหน่งที่ 0

# List Methods
numbers = [3, 1, 4, 1, 5]
numbers.sort() # เรียงลำดับ
numbers.reverse() # กลับลำดับ
print(len(numbers)) # ความยาว
print(numbers.count(1)) # นับจำนวน 1

4. Tuple (ทูเพิล):

Tuple คล้าย List แต่เปลี่ยนแปลงไม่ได้ (Immutable)

# สร้าง Tuple
coordinates = (10, 20)
rgb = (255, 128, 0)

# เข้าถึงข้อมูล
print(coordinates[0]) # 10

# Tuple Unpacking
x, y = coordinates
print(x, y) # 10 20

5. Dictionary (พจนานุกรม):

Dictionary เก็บข้อมูลแบบ Key-Value Pairs

# สร้าง Dictionary
person = {
    "name": "Alice",
    "age": 25,
    "city": "Bangkok"
}

# เข้าถึงข้อมูล
print(person["name"]) # Alice
print(person.get("age")) # 25

# แก้ไขข้อมูล
person["age"] = 26
person["email"] = "alice@email.com"

# ลบข้อมูล
del person["city"]
person.pop("email")

# Dictionary Methods
print(person.keys()) # dict_keys(['name', 'age'])
print(person.values()) # dict_values(['Alice', 26])
print(person.items()) # dict_items([('name', 'Alice'), ('age', 26)])

6. Set (เซต):

Set เป็น Collection ที่ไม่มีลำดับและไม่มีค่าซ้ำ

# สร้าง Set
numbers = {1, 2, 3, 4, 5}
fruits = {"apple", "banana", "orange"}

# เพิ่มข้อมูล
fruits.add("grape")

# ลบข้อมูล
fruits.remove("apple")

# Set Operations
a = {1, 2, 3}
b = {3, 4, 5}
print(a | b) # Union: {1, 2, 3, 4, 5}
print(a & b) # Intersection: {3}
print(a - b) # Difference: {1, 2}

7. Boolean (บูลีน):

is_active = True
is_deleted = False

# Truthy และ Falsy Values
bool(0) # False
bool("") # False
bool([]) # False
bool(None) # False
bool(1) # True
bool("text") # True
bool([1, 2]) # True

Control Flow (การควบคุมการทำงาน)

Control Flow ช่วยให้โปรแกรมสามารถตัดสินใจและทำงานซ้ำได้

1. If-Elif-Else Statement:

age = 18

if age < 13:
    print("เด็ก")
elif age < 20:
    print("วัยรุ่น")
elif age < 60:
    print("ผู้ใหญ่")
else:
    print("ผู้สูงอายุ")

# Ternary Operator (If แบบสั้น)
status = "ผ่าน" if score >= 50 else "ไม่ผ่าน"

2. For Loop:

# วนลูปใน List
fruits = ["apple", "banana", "orange"]
for fruit in fruits:
    print(fruit)

# วนลูปด้วย range()
for i in range(5): # 0 ถึง 4
    print(i)

for i in range(1, 6): # 1 ถึง 5
    print(i)

for i in range(0, 10, 2): # 0, 2, 4, 6, 8
    print(i)

# วนลูปใน Dictionary
person = {"name": "Alice", "age": 25}
for key, value in person.items():
    print(f"{key}: {value}")

# enumerate() - ได้ทั้ง index และ value
for index, fruit in enumerate(fruits):
    print(f"{index}: {fruit}")

3. While Loop:

# While Loop พื้นฐาน
count = 0
while count < 5:
    print(count)
    count += 1

# While True (วนลูปไม่สิ้นสุด)
while True:
    answer = input("ต้องการออกหรือไม่? (y/n): ")
    if answer == "y":
        break # ออกจากลูป
    print("ทำงานต่อ...")

4. Break, Continue, Pass:

# break - ออกจากลูป
for i in range(10):
    if i == 5:
        break
    print(i) # พิมพ์ 0-4

# continue - ข้ามรอบนี้
for i in range(5):
    if i == 2:
        continue
    print(i) # พิมพ์ 0, 1, 3, 4

# pass - ไม่ทำอะไร (placeholder)
for i in range(5):
    if i == 2:
        pass # จะเขียนโค้ดทีหลัง
    print(i)

5. List Comprehension:

วิธีสร้าง List แบบสั้นและอ่านง่าย

# แบบปกติ
squares = []
for i in range(10):
    squares.append(i ** 2)

# List Comprehension
squares = [i ** 2 for i in range(10)]

# มีเงื่อนไข
even_squares = [i ** 2 for i in range(10) if i % 2 == 0]

# Dictionary Comprehension
squares_dict = {i: i ** 2 for i in range(5)}
# {0: 0, 1: 1, 2: 4, 3: 9, 4: 16}

Functions (ฟังก์ชัน)

Functions ช่วยให้เราสามารถแบ่งโค้ดเป็นส่วนๆ และนำกลับมาใช้ซ้ำได้

1. การสร้าง Function:

# Function พื้นฐาน
def greet():
    print("สวัสดี!")

greet() # เรียกใช้งาน

# Function ที่มี Parameter
def greet_name(name):
    print(f"สวัสดี {name}!")

greet_name("Alice")

# Function ที่ Return ค่า
def add(a, b):
    return a + b

result = add(5, 3)
print(result) # 8

2. Default Parameters:

def greet(name, greeting="สวัสดี"):
    print(f"{greeting} {name}!")

greet("Alice") # สวัสดี Alice!
greet("Bob", "Hello") # Hello Bob!

3. Keyword Arguments:

def create_profile(name, age, city):
    print(f"{name}, {age} ปี, อยู่ {city}")

# เรียกแบบระบุชื่อ parameter
create_profile(age=25, city="Bangkok", name="Alice")

4. *args และ **kwargs:

# *args - รับ arguments จำนวนไม่จำกัด
def sum_all(*numbers):
    total = 0
    for num in numbers:
        total += num
    return total

print(sum_all(1, 2, 3, 4, 5)) # 15

# **kwargs - รับ keyword arguments จำนวนไม่จำกัด
def print_info(**info):
    for key, value in info.items():
        print(f"{key}: {value}")

print_info(name="Alice", age=25, city="Bangkok")

5. Lambda Functions:

Function แบบสั้นที่ไม่มีชื่อ

# Lambda พื้นฐาน
square = lambda x: x ** 2
print(square(5)) # 25

# ใช้กับ map()
numbers = [1, 2, 3, 4, 5]
squared = list(map(lambda x: x ** 2, numbers))
print(squared) # [1, 4, 9, 16, 25]

# ใช้กับ filter()
even = list(filter(lambda x: x % 2 == 0, numbers))
print(even) # [2, 4]

6. Docstrings:

การเขียนคำอธิบาย Function

def calculate_area(width, height):
    """
    คำนวณพื้นที่สี่เหลี่ยม
    
    Parameters:
        width (float): ความกว้าง
        height (float): ความสูง
    
    Returns:
        float: พื้นที่
    """
    return width * height

# ดู docstring
print(calculate_area.__doc__)

Libraries และ Modules

Python มี Libraries มากมายที่ช่วยให้เราทำงานได้เร็วขึ้น ไม่ต้องเขียนทุกอย่างเอง

1. การ Import Module:

# Import ทั้ง module
import math
print(math.pi) # 3.141592653589793
print(math.sqrt(16)) # 4.0

# Import เฉพาะที่ต้องการ
from math import pi, sqrt
print(pi)
print(sqrt(16))

# Import ทั้งหมด (ไม่แนะนำ)
from math import *

# Import แล้วตั้งชื่อใหม่
import numpy as np
import pandas as pd

2. Built-in Modules ที่ใช้บ่อย:

  • math - ฟังก์ชันทางคณิตศาสตร์
  • random - สุ่มตัวเลข
  • datetime - จัดการวันที่และเวลา
  • os - ทำงานกับระบบปฏิบัติการ
  • sys - ทำงานกับ Python interpreter
  • json - จัดการไฟล์ JSON
  • re - Regular Expression

3. ตัวอย่างการใช้งาน:

# random
import random
print(random.randint(1, 10)) # สุ่มเลข 1-10
print(random.choice(['a', 'b', 'c'])) # สุ่มเลือก

# datetime
from datetime import datetime
now = datetime.now()
print(now.strftime("%Y-%m-%d %H:%M:%S"))

# os
import os
print(os.getcwd()) # โฟลเดอร์ปัจจุบัน
os.mkdir("new_folder") # สร้างโฟลเดอร์

# json
import json
data = {"name": "Alice", "age": 25}
json_string = json.dumps(data)
print(json_string)

4. การติดตั้ง External Libraries:

ใช้ pip (Python Package Installer) ในการติดตั้ง

# ติดตั้ง library
pip install requests
pip install numpy
pip install pandas

# ติดตั้งหลาย libraries พร้อมกัน
pip install requests numpy pandas

# ติดตั้งจาก requirements.txt
pip install -r requirements.txt

# อัพเดท library
pip install --upgrade requests

# ถอนการติดตั้ง
pip uninstall requests

5. Popular Libraries:

  • NumPy - การคำนวณทางคณิตศาสตร์และ Array
  • Pandas - การจัดการและวิเคราะห์ข้อมูล
  • Matplotlib - สร้างกราฟและ Visualization
  • Requests - HTTP requests
  • BeautifulSoup - Web scraping
  • Flask/Django - Web frameworks
  • TensorFlow/PyTorch - Machine Learning
  • OpenCV - Computer Vision

6. การสร้าง Module ของตัวเอง:

สร้างไฟล์ mymodule.py:

# mymodule.py
def greet(name):
    return f"สวัสดี {name}!"

def add(a, b):
    return a + b

PI = 3.14159

ใช้งานใน main.py:

# main.py
import mymodule

print(mymodule.greet("Alice"))
print(mymodule.add(5, 3))
print(mymodule.PI)

โปรเจคตัวอย่าง

มาลองสร้างโปรเจคง่ายๆ เพื่อฝึกฝนทักษะ Python กันเถอะ

โปรเจค 1: เครื่องคิดเลข

def calculator():
    print("=== เครื่องคิดเลข ===")
    print("1. บวก")
    print("2. ลบ")
    print("3. คูณ")
    print("4. หาร")
    
    choice = input("เลือกการดำเนินการ (1-4): ")
    num1 = float(input("ใส่ตัวเลขที่ 1: "))
    num2 = float(input("ใส่ตัวเลขที่ 2: "))
    
    if choice == '1':
        print(f"ผลลัพธ์: {num1 + num2}")
    elif choice == '2':
        print(f"ผลลัพธ์: {num1 - num2}")
    elif choice == '3':
        print(f"ผลลัพธ์: {num1 * num2}")
    elif choice == '4':
        if num2 != 0:
            print(f"ผลลัพธ์: {num1 / num2}")
        else:
            print("ไม่สามารถหารด้วย 0 ได้")

calculator()

โปรเจค 2: เกมทายตัวเลข

import random

def guess_number():
    number = random.randint(1, 100)
    attempts = 0
    
    print("=== เกมทายตัวเลข ===")
    print("ทายตัวเลขระหว่าง 1-100")
    
    while True:
        guess = int(input("ทายตัวเลข: "))
        attempts += 1
        
        if guess < number:
            print("น้อยเกินไป!")
        elif guess > number:
            print("มากเกินไป!")
        else:
            print(f"ถูกต้อง! ใช้ {attempts} ครั้ง")
            break

guess_number()

โปรเจค 3: To-Do List

def todo_list():
    tasks = []
    
    while True:
        print("\n=== To-Do List ===")
        print("1. เพิ่มงาน")
        print("2. แสดงงานทั้งหมด")
        print("3. ลบงาน")
        print("4. ออก")
        
        choice = input("เลือก (1-4): ")
        
        if choice == '1':
            task = input("ใส่งาน: ")
            tasks.append(task)
            print("เพิ่มงานแล้ว!")
        elif choice == '2':
            if tasks:
                for i, task in enumerate(tasks, 1):
                    print(f"{i}. {task}")
            else:
                print("ไม่มีงาน")
        elif choice == '3':
            num = int(input("เลขที่งาน: ")) - 1
            if 0 <= num < len(tasks):
                tasks.pop(num)
                print("ลบงานแล้ว!")
        elif choice == '4':
            break

todo_list()

โปรเจค 4: Weather API

import requests

def get_weather(city):
    api_key = "YOUR_API_KEY"
    url = f"http://api.openweathermap.org/data/2.5/weather"
    params = {
        "q": city,
        "appid": api_key,
        "units": "metric"
    }
    
    response = requests.get(url, params=params)
    data = response.json()
    
    if response.status_code == 200:
        temp = data['main']['temp']
        desc = data['weather'][0]['description']
        print(f"{city}: {temp}°C, {desc}")
    else:
        print("ไม่พบข้อมูล")

get_weather("Bangkok")

โปรเจค 5: File Manager

import os

def file_manager():
    while True:
        print("\n=== File Manager ===")
        print("1. แสดงไฟล์")
        print("2. สร้างไฟล์")
        print("3. ลบไฟล์")
        print("4. อ่านไฟล์")
        print("5. ออก")
        
        choice = input("เลือก (1-5): ")
        
        if choice == '1':
            files = os.listdir()
            for f in files:
                print(f)
        elif choice == '2':
            name = input("ชื่อไฟล์: ")
            content = input("เนื้อหา: ")
            with open(name, 'w') as f:
                f.write(content)
            print("สร้างไฟล์แล้ว!")
        elif choice == '3':
            name = input("ชื่อไฟล์: ")
            if os.path.exists(name):
                os.remove(name)
                print("ลบไฟล์แล้ว!")
        elif choice == '4':
            name = input("ชื่อไฟล์: ")
            if os.path.exists(name):
                with open(name, 'r') as f:
                    print(f.read())
        elif choice == '5':
            break

file_manager()

แหล่งเรียนรู้เพิ่มเติม

มีแหล่งเรียนรู้ Python มากมายทั้งภาษาไทยและภาษาอังกฤษ

เว็บไซต์เรียนรู้:

  • Python.org - เอกสารอย่างเป็นทางการ
  • W3Schools Python - Tutorial พื้นฐานที่เข้าใจง่าย
  • Real Python - บทความและ Tutorial คุณภาพสูง
  • GeeksforGeeks - ตัวอย่างโค้ดและคำอธิบายละเอียด
  • Codecademy - เรียนแบบ Interactive
  • DataCamp - เน้น Data Science

YouTube Channels:

  • Corey Schafer - Tutorial Python ที่ดีที่สุด
  • Programming with Mosh - เหมาะสำหรับผู้เริ่มต้น
  • Tech With Tim - โปรเจคและ Tutorial
  • Sentdex - Machine Learning และ Data Science
  • freeCodeCamp - คอร์สยาวๆ ฟรี

หนังสือแนะนำ:

  • Python Crash Course - เหมาะสำหรับผู้เริ่มต้น
  • Automate the Boring Stuff with Python - เน้น Practical
  • Fluent Python - สำหรับระดับกลางถึงสูง
  • Python Cookbook - เทคนิคและ Best Practices

Online Courses:

  • Coursera - Python for Everybody (University of Michigan)
  • Udemy - 100 Days of Code: The Complete Python Pro Bootcamp
  • edX - Introduction to Computer Science (MIT)
  • Pluralsight - Python Path

Practice Platforms:

  • LeetCode - ฝึกแก้ปัญหาและเตรียมสัมภาษณ์
  • HackerRank - Challenges และ Competitions
  • Codewars - Kata และ Ranking System
  • Project Euler - ปัญหาทางคณิตศาสตร์

Communities:

  • Stack Overflow - ถามตอบปัญหา
  • Reddit r/learnpython - Community สำหรับผู้เริ่มต้น
  • Python Discord - Chat และถามตอบแบบ Real-time
  • Dev.to - บทความและ Tutorial

สนับสนุน / ช้อปอุปกรณ์ / เข้าร่วม Community

หากคุณสนใจอุปกรณ์สำหรับเขียน Python บน Hardware เช่น Raspberry Pi, ESP32, MicroPython หรืออยากพูดคุยแลกเปลี่ยนความรู้กับเพื่อนๆ ในสาย GlobalByte สามารถกดปุ่มด้านล่างนี้ได้เลย

เนื้อหาจัดทำโดย GlobalByte - ศูนย์รวมความรู้ด้าน Programming และ IoT

แท็ก


Blog posts

เข้าสู่ระบบ

ลืมรหัสผ่านใช่ไหม?

ยังไม่มีบัญชีใช่ไหม?
สร้างบัญชี