class Animal():
def __init__(self,name,age):
self.name=name
self.__age=age
dog = Animal('aa',1)
print(dog.name)
print(dog.__age)
def __init__(self,name,age):
self.name=name
self.__age=age
dog = Animal('aa',1)
print(dog.name)
print(dog.__age)
2021-05-28
class Animal():
count=0
def __init__(self,name,age):
self.name = name
self.age = age
Animal.count +=1
dog = Animal('aa',1)
cat = Animal('bb',2)
print(Animal.count)
count=0
def __init__(self,name,age):
self.name = name
self.age = age
Animal.count +=1
dog = Animal('aa',1)
cat = Animal('bb',2)
print(Animal.count)
2021-05-28
class Animal():
def __init__(self,name,age):
self.name=name
self.age=age
dog = Animal('wang',1)
cat = Animal('miao',2)
print(dog.name,dog.age,cat.name,cat.age)
def __init__(self,name,age):
self.name=name
self.age=age
dog = Animal('wang',1)
cat = Animal('miao',2)
print(dog.name,dog.age,cat.name,cat.age)
2021-05-28
# Enter a code
class Animal(object):
def __init__(self, name, age):
self.name = name
self._age = age
print(Animal._age)
class Animal(object):
def __init__(self, name, age):
self.name = name
self._age = age
print(Animal._age)
2021-05-25
# Enter a code
class Animal(object):
count=0
def __init__(self,name,age):
self.name=name
self.age=age
Animal.count=Animal.count+1
pass
print(Animal.count)
dog=Animal('Bob',12)
print(Animal.count)
cat=Animal('Tina',19)
print(Animal.count)
print(dog.name,dog.age)
class Animal(object):
count=0
def __init__(self,name,age):
self.name=name
self.age=age
Animal.count=Animal.count+1
pass
print(Animal.count)
dog=Animal('Bob',12)
print(Animal.count)
cat=Animal('Tina',19)
print(Animal.count)
print(dog.name,dog.age)
2021-05-19
# Enter a code
class Animal(object):
def __init__(self,name,age):
self.name=name
self.age=age
pass
dog=Animal('Bob',12)
cat=Animal('Tina',19)
print(dog.name,dog.age)
注:
1.init首尾下划线各有两条
2.不可以直接print(dog),要具体化
class Animal(object):
def __init__(self,name,age):
self.name=name
self.age=age
pass
dog=Animal('Bob',12)
cat=Animal('Tina',19)
print(dog.name,dog.age)
注:
1.init首尾下划线各有两条
2.不可以直接print(dog),要具体化
2021-05-19
# Enter a code
class Animal():pass
dog=Animal()
cat=Animal()
dog.name='dog'
dog.age=12
cat.name='cat'
cat.age=19
print(cat.age,cat.name)
class Animal():pass
dog=Animal()
cat=Animal()
dog.name='dog'
dog.age=12
cat.name='cat'
cat.age=19
print(cat.age,cat.name)
2021-05-19
# Enter a code
class Animal():pass
dog=Animal()
cat=Animal()
class Animal():pass
dog=Animal()
cat=Animal()
2021-05-19
教3.x的python的教程里用的解释器居然还是2.x,还得自己引入《未来》语法支持,答案里标注一个本地练习就行了?我一进来先看答案?线上编辑功能摆好看的?这简直就离谱,都多久了,这玩意没人维护升级吗?
2021-05-11