import math
def add(x,y,f):
return f(x) +f(y)
print(add(4, 16, math.sqrt))
def add(x,y,f):
return f(x) +f(y)
print(add(4, 16, math.sqrt))
2021-05-29
最赞回答 / 奶香馒头
我明白了,super(Teacher,self).__init__(name,gender)这是python2.x中的语法,class括号里要带object,python3.x语法里class可以不带
2021-05-28
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