全部 新建

user:thomas 由使用者建立的 Gists

title:mygist Gists 的標題

filename:myfile.txt Gists 的檔案名稱

extension:yml Gists 的副檔名

language:go Gists 的程式語言

topic:homelab gists with given topic

登錄


全部 新建 登錄

All gists matching topic typing

倒序排序 創建
順序排序 創建
倒序排序 更新
順序排序 更新

timmy / 使用 typing 進行型別註解

0 喜歡
0 分支
1 檔案
最後活躍 9 months ago
typing 模組允許為 Python 變數、函式參數和回傳值指定型別,有助於提升程式碼可讀性、可維護性,並可搭配靜態分析工具(如 mypy)檢查型別錯誤。
python static-analysis type-hinting typing
1 from typing import Any, Dict, List, Optional, Tuple, Union
2
3 # 函式使用型別註解
4 def process_data(
5 data: List[Dict[str, Union[int, float]]],
6 metadata: Optional[Dict[str, Any]] = None
7 ) -> Tuple[int, float]:
8 """計算資料的總和與平均值"""
9 total = sum(item["value"] for item in data)
10 avg = total / len(data) if data else 0
上一頁 下一頁

由 Opengist 提供支持 ⋅ Load: 15ms⋅

繁體中文
Čeština Deutsch English Español Français Magyar Italiano 日本語 Polski Português Русский Türkçe Українська 中文 繁體中文