myabs = lambda x: -x if x < 0 else x
这句代码,看了半天,才理解,原来是等同与:
def myabs(x):
if(x<0):
return -x
else :
return x
print myabs(-23)
这句代码,看了半天,才理解,原来是等同与:
def myabs(x):
if(x<0):
return -x
else :
return x
print myabs(-23)
2018-04-06
def get_grade(self):
if self.__score<60:
return 'C'
elif self.__score<80:
return 'B'
else:
return 'A'
if self.__score<60:
return 'C'
elif self.__score<80:
return 'B'
else:
return 'A'
2018-04-06
已采纳回答 / 慕慕8321286
self.key的时候,key就不是指的for循环里面的key了, 而是self的一个属性,不信你可以试试将最后的输出xiaoming.job换成xiaoming.key 就会发现输出的值为Student
2018-04-06
当函数的参数不确定时,可以使用*args 和**kw(全称**kwargs),*args 没有key值,**kw有key值。传形参时,**kw对应的参数里=左边的可以当成key,=右边的可以当成value,感觉**kw可以当作容纳多个key和value的dictionary
2018-04-06
def count():
fs = []
for i in range(1, 4):
def f(j):
def g():
return j*j
return g
r = f(i)
fs.append(r)
return fs
f1, f2, f3 = count()
print f1(), f2(), f3()
fs = []
for i in range(1, 4):
def f(j):
def g():
return j*j
return g
r = f(i)
fs.append(r)
return fs
f1, f2, f3 = count()
print f1(), f2(), f3()
2018-04-05
def count():
fs = []
for i in range(1, 4):
def f(j):
def g():
return j*j
return g
r = f(i)
fs.append(r)
return fs
f1, f2, f3 = count()
print f1(), f2(), f3()
fs = []
for i in range(1, 4):
def f(j):
def g():
return j*j
return g
r = f(i)
fs.append(r)
return fs
f1, f2, f3 = count()
print f1(), f2(), f3()
2018-04-05