class animal:pass
dog=animal()
cat=animal()
dog.name = 'wangwang'
dog.sex = 'girl'
dog.age = 13
cat.name = "miaomiao"
cat.sex = 'boy'
cat.age = 6
print(dog.name,dog.age,dog.sex)
print(cat.name,cat.age,cat.sex)
dog=animal()
cat=animal()
dog.name = 'wangwang'
dog.sex = 'girl'
dog.age = 13
cat.name = "miaomiao"
cat.sex = 'boy'
cat.age = 6
print(dog.name,dog.age,dog.sex)
print(cat.name,cat.age,cat.sex)
2021-02-25
a,b=b,a+b 相当于:
temp=b #先保存b的原值
b=a+b #赋b新值
a=temp #将b的原值赋予a
实际就是C语言中的数据交换过程,也可理解为先计算右边后赋值。
temp=b #先保存b的原值
b=a+b #赋b新值
a=temp #将b的原值赋予a
实际就是C语言中的数据交换过程,也可理解为先计算右边后赋值。
2021-02-25
namelist = ['alice', 'BOB', 'CanDY']
def f(l):
return l.capitalize()
for item in map(f,namelist):
print(item)
def f(l):
return l.capitalize()
for item in map(f,namelist):
print(item)
2021-02-12
已采纳回答 / 柳随风
calss Anmial(object): def __init__(self,name,age): self.name = name self.age = agedog = Anmial('Tim',4)cat = Anmial('Aim',5)print(dog.name)print(dog.age)print(cat.name)print(cat.age)<...code...>
2021-01-23
已采纳回答 / 柳随风
calss Anmial(object): count = 0 def __init__(self,name,age): self.name = name self.age = age Animal.count =Animal.count + 1dog = Animal('wangwang',1)print(Animal.count)cat = Animal('mimi',3)print(Animal.count)pig ...
2021-01-23
已采纳回答 / 柳随风
calss Animal(object): def __init__(self,name,age) self.name = name self.age = age dog = Animal('Tim',4) cat = Animal('Aim',5) print(dog.name) print(dog.age) print(cat.name) print(cat.age)<...code...>
2021-01-22