Python
Python是一種廣泛使用的直譯式、進階程式、通用型程式語言,由吉多·范羅蘇姆創造,第一版釋出於1991年。Python是ABC語言的後繼者,也可以視之為一種使用傳統中綴表達式的LISP方言。Python的設計哲學強調代碼的可讀性和簡潔的語法。相比於C++或Java,Python讓開發者能夠用更少的代碼表達想法。
Learning
Online Interpreter https://www.onlinegdb.com/online_python_interpreter https://repl.it/langua...
pip
Installation Tutorials Install packages in a virtual environment using pip and venv - Python ...
Example: IP Geolocation Tool
maxmind_db_ip_geolocator.py Original Post: Python Basics for Hackers, Part 4: How to Find the Ex...
Tips
編碼 UTF-8 宣告 #!/usr/bin/python # -*- coding: utf-8 -*- Find all installed modules help("module...
Functions
參數類型定義範例 def _gpt_parse_images( image_infos: List[Tuple[str, List[str]]], prom...
THSRC API
Links TDX 運輸資料通服務 TDX 會員註冊 TDX運輸資料流通服務API介接範例程式碼說明 TDX - 高鐵 API 說明 雙鐵API資料使用注意事項 API 虛擬點數...
JSON
Tutorials How to Transform JSON Data to Match Any Schema JSON to dict json.loads 用來轉換資料; j...
Datetime
時間格式代碼 %d:以十進製表示的月份中的第幾天,填充零。 %m:十進製表示的月份,零填充。 %y:以零填充的十進製表示法的年份的最後兩位數字。 %Y:以十進製表示的四位年份數字,零...
One-Liners
1) Multiple Variable Assignment # Traditional way a = 1 b = "ok" c = False # Pythonic way...
List 串列
串列是任何類型元素的序列,並且是可變的。用於儲存項目集合,它們可以包含任何型別的資料,並以方(中)括號表示。 a = [1, 2, 3, 4, 5] b = ['mango', 'pinea...
String 字串
字串是字元序列且是不可變的。以單引號或雙引號括起來的多個字元的集合,可以包含字母、數字和特殊字元。 Concatenate secret_password = 'jhk7GSH8ds' p...
Installation
Alternatives 變更 python 指令的預設路徑 alternatives --set python /usr/bin/python3 # Or alternatives -...
Unit Test
單元測試 目的:以隔離主程式的方式,對自訂的函式(function)與方法(method),提供指定的輸入參數與期待的輸出結果,以驗證相關程式碼是否有瑕疵或錯誤。 方法:撰寫額外的測試用...
Regular Expression
Basic Regex Character types \w matches with any alphanumeric character, including underline ...
Tuple 元組
元組類似於清單,是任何類型的元素序列,但它們是不可變的,它們以括號表示。 符號用括號 內容不可變更 處理大量資料比 List 節省記憶體 讀取速度比串列(List)快 a = ...
Dictionary 字典
不像序列是由一個範圍內的數字當作索引,dictionary 是由鍵 (key) 來當索引,鍵可以是任何不可變的類型;字串和數字都可以當作鍵。Tuple 也可以當作鍵,如果他們只含有字串、數字或 ...
Google Python Course
Google Python 訓練課程
Course 1
Naming rules and conventions 命名規則與慣例 When assigning names to objects, programmers adhere to a s...
Dictionaries vs. Lists
Dictionaries are similar to lists, but there are a few differences: Both dictionaries and lists:...
Classes and methods
Defining classes and methods class ClassName: def method_name(self, other_parameters): ...
Examples
登入紀錄報告 Custom Class Dictionary/Set/List Data Set Methods def get_event_date(event): re...
Course 2
Understanding Slowness Slow Web Server ab - Apache benchmark tool ab -n 500 site.example.com ...
Python Cheat Sheet
String Methods Set/List/Dictionary Methods List methods List methods Data Structures ...
Set 集合
當您想要儲存一堆元素,並確定這些元素只出現一次時,就會使用集合(set)。集合(set)的元素也必須是不可變的。您可以將其視為字典 (dictionary) 中沒有關聯值 (value) 的鍵 ...
CSV
Reading CSV files csv.reader(<file-object>, delimiter=':') : input is CSV file. the parameter ...
Error Handling
捕捉錯誤與異常訊息 適用實例: A file doesn’t exist A network or database connection fails Your ...
Binary Search
二分搜尋(Binary Search)是一種高效的搜尋演算法,用於在已排序的串列(List)中尋找特定元素的位置或值。 前提條件: 資料集合必須是已排序的,可以是升序或降序排列。這是因為二分...
Debug
Debugging assert 主要用在開發與測試階段 可用在程式的條件測試 assert <condition>, <message> : 如果 condition 為 True...
Python Virtual Environment
Tutorials How to Install and Manage Python Versions in Linux - Make Tech Easier uv 用途: 套...
Custom Setup.py
為自己的專案訂製一個 setup.py 安裝程序 Commands Install all dependencies cd <your-repo> pip install -e . ...
FastAPI
Getting Started
Introduction FastAPI is a modern, high-performance web framework for building APIs using Python....
Upload File
Tutorials FastAPI File Upload Download Tutorial Installation pip install fastapi uvicorn p...
Deployment
Tutorials Sample FastAPI application for deployment in the production
Authentication
Tutorials Authentication and Authorization with FastAPI: A Complete Guide | Better Stack Commu...
Example: Internet Speed Tacker
Prerequisites sudo apt install speedtest-cli internet_speed_tracker.py #!/usr/bin/env python3 ...
Flask API
Tutorials [Day 29] 使用 Python Flask 架設 API 吧! - iT 邦幫忙::一起幫忙解決難題,拯救 IT 人的一天 Basic Example f...