class Animal(object):
pass
dog = Animal()
cat = Animal()
print(dog)
print(cat)
print(dog == cat)
pass
dog = Animal()
cat = Animal()
print(dog)
print(cat)
print(dog == cat)
2025-03-08
最新回答 / tinghai
執(zhí)行報(bào)錯(cuò):Traceback (most recent call last):? File "E:\python\example\lizi.py", line 283, in <module>? ? student = Student('Alice',100)? ? ? ? ? ? ? ^^^^^^^^^^^^^^^^^^^^? File "E:\python\example\lizi.py", line 280, in __init__? ? super(Student, self).__i...
2025-02-07
repr是“representation”的縮寫(xiě),意為“表示”或“表達(dá)”。
2025-02-01
super詳解:https://www.runoob.com/w3cnote/python-super-detail-intro.html
2025-02-01
最新回答 / 英寧
第4行的__count是__init__方法里一個(gè)局部變量, 跟第2行的__count沒(méi)有什么關(guān)系,并不會(huì)改變第2行的類(lèi)私有屬性的值。
2024-12-28
class Animal(object):
def __init__(self,name,age):
self.name=name
self.age=age
pass
dog: Animal = Animal('dog',3)
cat = Animal('cat',5)
def __init__(self,name,age):
self.name=name
self.age=age
pass
dog: Animal = Animal('dog',3)
cat = Animal('cat',5)
2024-09-19
寫(xiě)的一言難盡。。。。推薦大家耐心看這個(gè)算了廖雪峰python學(xué)習(xí):https://liaoxuefeng.com/books/python/introduction/index.html
2024-09-13
類(lèi)的私有屬性和方法指的是只能在類(lèi)的內(nèi)部使用,而不能在類(lèi)外使用的屬性和方法。
2024-08-28
在python中定義私有變量和私有方法只需要在變量名或函數(shù)名前加上 "__"兩個(gè)下劃線
2024-08-28