class init 多載方式 === 1. 另外實作客製的`new()` 來建立物件, 切記要 `return self` ```python= class People: self.name = "" self.age = 0 def __init__(self): pass def new(self, name, age): self.name = name self.age = age return self ``` 2. 與 `__init__` 寫在一起 ```python= class People: def __init__(self, name = None, age = 0): if name = None: self.name = "NoName" self.age = 0 else: self.name = name self.age = age ``` ## Ref. [Python 入門指南 單元 11 - __init__() 方法]([https://](http://kaiching.org/pydoing/py-guide/unit-11-init.html)) ###### tags: `語法相關`
×
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