這是一份 18 小時完整的 Python 入門教材,設計給 零基礎的學習者,讓你能在 18 小時內學會 Python 基礎、進階功能、數據處理、爬蟲、資料分析與自動化應用。本教材適合 自學、短期課程、工作應用與專案開發,並以 每小時一個主題的方式 進行學習。
📘 Python 18 小時完整入門
⌛ 學習規劃
時間 | 內容 |
---|---|
第 1-6 小時 | Python 基礎語法、流程控制、函式、資料結構 |
第 7-12 小時 | 物件導向、檔案處理、網路爬蟲、自動化應用 |
第 13-18 小時 | 數據處理、資料分析、專案實作 |
🔹 第一階段(基礎語法與資料結構)
Python 是一種簡潔易學的程式語言,適合新手入門。本階段將學習 Python 的基本語法、條件判斷、迴圈、函式與資料結構。
📌 第 1 小時:Python 基礎語法
Python 具有 動態語型,不需要定義變數型別,並且使用 縮排 來區分程式區塊。
🔹 變數與數據類型
name = input("請輸入你的名字: ")
print(f"Hello, {name}!")
a, b = 10, 3
print(a + b, a - b, a * b, a / b, a % b)
🔹 重點:
- 變數宣告 不需要類型(動態語型)
- f-string 可以讓變數與字串結合
- 運算符 包含
+ - * / %
📌 第 2 小時:條件判斷
Python 使用 if-elif-else
來進行條件判斷:
score = int(input("請輸入分數: "))
if score >= 90:
print("A")
elif score >= 80:
print("B")
elif score >= 70:
print("C")
else:
print("不及格")
🔹 重點:
- 條件語法 必須以
:
結尾 - 縮排表示區塊(不使用
{}
)
📌 第 3 小時:迴圈(for, while)
Python 提供 for
與 while
來處理重複執行的內容:
# for 迴圈
for i in range(1, 6):
print(f"第 {i} 次")
# while 迴圈
n = 5
while n > 0:
print(f"倒數: {n}")
n -= 1
🔹 重點:
range(n)
產生0 ~ n-1
的整數while
適用於 條件控制的重複執行
📌 第 4 小時:函式與模組
Python 提供函式來封裝程式邏輯,提高 程式的可讀性與模組化。
def greet(name):
return f"Hello, {name}!"
print(greet("Alice"))
🔹 重點:
- 函式定義 使用
def
,回傳值用return
- import 模組 可載入現有的功能
📌 第 5 小時:列表與字典
fruits = ["apple", "banana", "cherry"]
fruits.append("orange") # 新增元素
print(fruits)
student = {"name": "John", "age": 18}
print(student["name"])
🔹 重點:
- 列表(List) 使用
[]
- 字典(Dictionary) 使用
{}
並以key:value
存取
📌 第 6 小時:集合與元組
nums = {1, 2, 3, 4}
nums.add(5)
print(nums)
coordinates = (10, 20)
print(coordinates[0])
🔹 重點:
- 集合(Set) 無重複元素
- 元組(Tuple) 不可變動
🔹 第二階段(進階應用)
本階段學習 物件導向、檔案處理、網路爬蟲、自動化應用,幫助你寫出更具彈性的程式。
📌 第 7 小時:物件導向程式設計 (OOP)
class Person:
def __init__(self, name, age):
self.name = name
self.age = age
def greet(self):
print(f"Hi, I'm {self.name}.")
p1 = Person("Alice", 25)
p1.greet()
🔹 重點:
__init__
為 建構函式self
代表物件自身
📌 第 8 小時:檔案處理
with open("test.txt", "w") as file:
file.write("Hello, Python!")
with open("test.txt", "r") as file:
content = file.read()
print(content)
🔹 重點:
open("檔案", "模式")
,模式為"r"
(讀取) 或"w"
(寫入)
📌 第 10 小時:網路爬蟲
import requests
url = "https://www.example.com"
response = requests.get(url)
print(response.text)
🔹 重點:
requests.get(url)
取得網頁內容
🔹 第三階段(數據分析與專案)
學習 資料分析、數據視覺化與實作應用。
📌 第 13 小時:NumPy
import numpy as np
arr = np.array([1, 2, 3, 4])
print(arr * 2)
🔹 重點:
- NumPy 適用於 矩陣與數值運算
📌 第 14 小時:Pandas
import pandas as pd
data = {"name": ["Alice", "Bob"], "age": [25, 30]}
df = pd.DataFrame(data)
print(df)
🔹 重點:
- Pandas 適用於 資料表處理
📌 第 16-18 小時:專案應用
🟢 猜數字遊戲
import random
number = random.randint(1, 10)
🟢 簡易計算機
def add(x, y):
return x + y
🟢 網路爬蟲應用
import requests
from bs4 import BeautifulSoup
🎯 18 小時 Python 完整入門總結
✅ 基礎語法、進階應用
✅ 資料處理、爬蟲、自動化
✅ 數據分析、專案應用
這份教材 完整涵蓋 Python 必學知識,讓你學完後 可應用於開發、工作、學術與專案!🚀
沒有留言:
張貼留言