def is_sqr(x):
return x % math.sqrt(x)==0 #这个写法真是仁者见仁啊
print filter(is_sqr, range(1, 101))
return x % math.sqrt(x)==0 #这个写法真是仁者见仁啊
print filter(is_sqr, range(1, 101))
2017-11-05
没有人对老师视频中的例子产生疑问吗?
函数式f2,f3是不是少写了一个参数x?
def f1(x):
return x * 2
def f2(x):
return x * x
def f3(x):
return x * x * x
函数式f2,f3是不是少写了一个参数x?
def f1(x):
return x * 2
def f2(x):
return x * x
def f3(x):
return x * x * x
2017-11-04
class Fib(object):
def __call__(self,num):
a,b,L = 0,1,[]
for x in range(num):
L.append(a)
a,b = b,a+b
return L
def __call__(self,num):
a,b,L = 0,1,[]
for x in range(num):
L.append(a)
a,b = b,a+b
return L
2017-11-04
class Student(Person):
__slots__ = ('score')
def __init__(self, name, gender,score):
super(Student,self).__init__(name,gender)
self.score = score
__slots__ = ('score')
def __init__(self, name, gender,score):
super(Student,self).__init__(name,gender)
self.score = score
2017-11-04
if self.score == s.score:
return cmp(self.name,s.name)
return -cmp(self.score,s.score)
return cmp(self.name,s.name)
return -cmp(self.score,s.score)
2017-11-04
def __cmp__(self, s):
if self.score > s.score:
return -1
elif self.score < s.score:
return 1
else:
if self.name < s.name:
return -1
elif self.name > s.name:
return 1
return 0
if self.score > s.score:
return -1
elif self.score < s.score:
return 1
else:
if self.name < s.name:
return -1
elif self.name > s.name:
return 1
return 0
2017-11-04
print isdir(r'/data/webroot') #True
print isdir(r'/data/webroot/resource') #False
被删了
print isdir(r'/data/webroot/resource') #False
被删了
2017-11-04
##没看懂啊。。。
class Fib(object):
def __init__(self):
pass
def __call__(self,num):
L=[0,1]
for i in range(num-2) :
L.append(L[-1]+L[-2])
return L
f = Fib()
print f(10)
class Fib(object):
def __init__(self):
pass
def __call__(self,num):
L=[0,1]
for i in range(num-2) :
L.append(L[-1]+L[-2])
return L
f = Fib()
print f(10)
2017-11-03
class Student(Person):
__slots__ = ('name', 'gender', 'score')
def __init__(self, name, gender, score):
super(Student, self).__init__( name, gender)
self.score = score
__slots__ = ('name', 'gender', 'score')
def __init__(self, name, gender, score):
super(Student, self).__init__( name, gender)
self.score = score
2017-11-03
@property
def grade(self):
if self.score >= 80:
return 'A'
elif self.score < 60:
return 'C'
else:
return 'B'
def grade(self):
if self.score >= 80:
return 'A'
elif self.score < 60:
return 'C'
else:
return 'B'
2017-11-03