# Enter a code
class Animal(object):
count = 0
def __init__(self,name,age):
self.name = name
self.age = age
Animal.count += 1
dog = Animal('wangwang',1)
cat = Animal('mimi',3)
print(dog.count)
print(cat.count)
class Animal(object):
count = 0
def __init__(self,name,age):
self.name = name
self.age = age
Animal.count += 1
dog = Animal('wangwang',1)
cat = Animal('mimi',3)
print(dog.count)
print(cat.count)
2022-09-03
# Enter a code
class Animal(object):
def __init__(self,name,age):
self.name = name
self.age = age
dog = Animal('dog',1)
cat = Animal('cat',2)
print(dog.name,dog.age)
print(cat.name,cat.age)
class Animal(object):
def __init__(self,name,age):
self.name = name
self.age = age
dog = Animal('dog',1)
cat = Animal('cat',2)
print(dog.name,dog.age)
print(cat.name,cat.age)
2022-08-31
# Enter a code
class Animal():
pass
dog = Animal()
cat = Animal()
print(dog)
print(cat)
print(dog == cat)
class Animal():
pass
dog = Animal()
cat = Animal()
print(dog)
print(cat)
print(dog == cat)
2022-08-30
class Animal(object):
__age = 2
def __init__(self, name, age):
self.name = name
cat = Animal('Kitty', '3')
print(cat.name)
print(cat._Animal__age)
__age = 2
def __init__(self, name, age):
self.name = name
cat = Animal('Kitty', '3')
print(cat.name)
print(cat._Animal__age)
2022-08-08
最赞回答 / 土斤土斤
这是一种代码简写的方式,称之为推导式,是通过一行代码完成循环判断,并遍历出一系列数据的编写代码方式。语法为:成员 for 循环 ... if 判断 ...而例子中的是为推导式中的一种类型,为列表推导式,结果是一个列表: [item for item in Iterable]所以 result = [item for item in map(lambda x: x * x, [1, 2, 3, 4, 5, 6, 7, 8, 9])] 是这一段的简写:result = []for i in map(lamb...
2022-07-31
最赞回答 / weixin_慕莱坞3215187
class Person(object): def __init__(self, name, gender, **kw): self.name = name self.gender = gender for k, v in kw.items(): setattr(self, k, v) p = Perso...
2022-06-24