class Animal(object):
def __init__(self, name, age):
self.name = name
self.age = age
dog = Animal('DD', 2)
cat = Animal('CC', 3)
print(dog.name + '--' + str(dog.age))
print(cat.name + '--' + str(cat.age))
def __init__(self, name, age):
self.name = name
self.age = age
dog = Animal('DD', 2)
cat = Animal('CC', 3)
print(dog.name + '--' + str(dog.age))
print(cat.name + '--' + str(cat.age))
2021-03-04
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
看了其他教程,发现继承方法用的是super().__init__(),和这里的不一样,把我搞懵了,查了下才知道原来这个教程是python2的写法
2021-01-19
def count():
fs = []
for i in range(1, 4):
def f():
return i*i
fs.append(f())
return fs
f1, f2, f3 = count()
print(f1,f2,f3)
f4=count()
print(f4)
fs = []
for i in range(1, 4):
def f():
return i*i
fs.append(f())
return fs
f1, f2, f3 = count()
print(f1,f2,f3)
f4=count()
print(f4)
2021-01-13