# Python 封包的設計與使用 ###### tags: `python` 引述: 包含模組的資料夾,用來整理、分類模組的程式 ## 專案檔案配置  如果沒有__init__.py則此資料夾不會被當封包來看待 __init__.py可以為空檔案 ## 基本語法 >import 封包名稱.模組名稱 >import 封包名稱.模組名稱 as 模組別名 ## 實作  **point.py檔** ```python= def distance(x,y): return (x**2+y**2)**0.5 ``` **line.py檔** ```python= def len(x1,y1,x2,y2): return ((x2-x1)**2) + ((y2-y1)**2) **0.5 def slope(x1,y1,x2,y2): return (y2-y1)/(x2-x1) ``` **main.py檔** ```python= import geometry.point; result = geometry.point.distance(3,4) print("距離",result) import geometry.line reslut = geometry.line.slope(1,1,3,3) print("斜率",result) ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up