[英]why do i get error for creating an object?
class Person:
def __init__(self, ids):
self.ids = ids
rahul = Person(100)
錯誤:
rahul = Person(100)
NameError: name 'Person' is not defined
有人可以告訴我這個簡單的代碼是什么問題嗎?
您在仍在創建類時(在類對象綁定到名稱Person
)正在調用Person
。 如果raul
確實應該是Person
的類屬性,則必須在定義類之后進行分配。
class Person:
def __init__(self, ids):
self.ids = ids
Person.rahul = Person(100)
我想象rahul = Person(100)
不應該縮進...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.