# 類別Class -類別與類別屬性 ## 定義->使用 * 定義: class 類別名稱: 定義封裝的變數 或定義封裝的函式(有兩種可能的屬性) class Test: x=3 def say(): print("Hello") * 使用: 類別名稱.屬性名稱(變數或函式) Test.x #取得x=3 Test.say() #呼叫函式 *第一個變數一定要寫self,不然會有bug(但似乎也是可以跑) > https://pythonhi.pixnet.net/blog/post/230749892 > 先說結論 養成一個好習慣,任何的class 宣告時,且習慣性的加入 def __init__(self,name1,name2,....):,讓它變成class宣告時的"起手式" 這邊代表宣告時會自動執行的函式 ###### tags: `python`
×
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