Python中小錯誤 之 object() takes no parameters
class Person :
population=0
def __init__(self,name):
self.name=name
print ('Initializing %s' % self.name)
Person.population+=1
def sayHi(self):
print ('hi,My name is %s.' % self.name)
def howMany(self):
if Person.population==1:
print ('I am the current population .')
else:
print ('We have %d persons here ' % Person.population)
swaroop=Person('Swaroop')
swaroop.sayHi()
swaroop.howMany()
kalam=Person('Abdul kalam')
kalam.sayHi()
kalam.howMany()
swaroop.sayHi()
swaroop.howMany()
如上面Python程式碼,是學習python類時遇到的一個小例子。但是在執行時會報錯:
Traceback (most recent call last):
File “E:/PythonStudy/objvar.py”, line 18, in
swaroop=Person(‘Swaroop’)
TypeError: object() takes no parameters
經過查閱資料才知道,是建構函式裡的下劃線的問題,
init(self,name)這個建構函式的左右下劃線都是兩個,我只用了一個,導致錯誤。
相關文章
- TypeError: object() takes no parametersErrorObject
- Python 錯誤之函式takes 0 positional arguments but 1 was givenPython函式
- Python 之 錯誤,除錯和測試Python除錯
- Python3類方法報錯takes 0 positional arguments but 1 was givenPython
- Python學習之錯誤除錯和測試Python除錯
- 訪問資料庫出現Object reference not set to an instance of an object錯誤資料庫Object
- eclipse中:The type java.lang.object cannot be resolved錯誤(jdk配置錯誤)EclipseJavaObjectJDK
- Python基礎之:Python中的異常和錯誤Python
- Python Template 錯誤Python
- Python之錯誤異常和檔案處理Python
- Python基礎之錯誤和異常講解Python
- Git 錯誤:fatel: loose object ... is corrupt 解決辦法GitObject
- [python]python錯誤集錦Python
- 1.python報錯:TypeError: 'int' object is not subscriptablePythonErrorObject
- Python錯誤處理Python
- Python 3 學習筆記之——錯誤和異常Python筆記
- C#操作SQLite資料庫時出現“Insufficient parameters supplied to the command”的錯誤C#SQLite資料庫
- python錯誤與異常Python
- 針對python錯誤 format()PythonORM
- Python錯誤重試方法Python
- Python 新手常犯的錯誤Python
- Python部分錯誤總結Python
- Python爬資料之全國中小學資訊Python
- Python報錯:TypeError: a bytes-like object is required, not ‘str‘PythonErrorObjectUI
- Flutter之異常和錯誤Flutter
- javascript之處理Ajax錯誤JavaScript
- Oracle之Rman常見錯誤Oracle
- python中sklearn包的錯誤Python
- Python忽略warning警告錯誤Python
- git錯誤:物件檔案為空(object-file-is-empty)解決方案Git物件Object
- 中小型企業常見網路安全錯誤盤點與應對
- Github錯誤之failed to push some refs toGithubAI
- [java基礎]之基本錯誤分析Java
- Golang通脈之錯誤處理Golang
- mysql 日誌之錯誤日誌MySql
- oracle錯誤之ORA-00600Oracle
- JVM parametersJVM
- Python錯誤:PyCharm 安裝出錯 Internal error,please。。。PythonPyCharmError