import math
def is_sqr(x):
return math.sqrt(x)%1==0
print filter(is_sqr, range(1, 101))
def is_sqr(x):
return math.sqrt(x)%1==0
print filter(is_sqr, range(1, 101))
2018-10-22
def calc_prod(lst):
def lazy_prod():
s = 1
for i in lst:
s = s * i
return s
return lazy_prod
f = calc_prod([1, 2, 3, 4])
print f()
def lazy_prod():
s = 1
for i in lst:
s = s * i
return s
return lazy_prod
f = calc_prod([1, 2, 3, 4])
print f()
2018-10-22
class Person(object):
__count = 0
def __init__(self, name):
self.name=name
Person.__count+=1
print Person.__count
p1 = Person('Bob')
p2 = Person('Alice')
try:
print Person.__count
except AttributeError:
print 'attributeError'
__count = 0
def __init__(self, name):
self.name=name
Person.__count+=1
print Person.__count
p1 = Person('Bob')
p2 = Person('Alice')
try:
print Person.__count
except AttributeError:
print 'attributeError'
2018-10-21
最赞回答 / 史高武
msecs就是一个参数来放(endTime-startTime)*1000的值,你可以用y=(endTime-startTime)*1000 也行啊,后面的mescs就换成y。而乘以1000因为time.time()单位是秒,这里用的毫秒ms,相当于单位的转换,之所以用msecs其实也就是为来让你明白这里是用毫秒的意思,,,
2018-10-21
import math
def is_sqr(x):
a = math.sqrt(x)
b = int(a)
if a-b==0.0:
return x
print filter(is_sqr, range(1,101))
def is_sqr(x):
a = math.sqrt(x)
b = int(a)
if a-b==0.0:
return x
print filter(is_sqr, range(1,101))
2018-10-20
最新回答 / 周四叶
from operator import attrgetter class Student(object): def __init__(self,name,score): self.name = name self.score = score def __str__(self): return '(%s:%s)'%(self.name,self.sc...
2018-10-18
可以通过的代码如下,需要处理异常:
class Person(object):
__count = 0
def __init__(self, name):
Person.__count += 1
self.name = name
print Person.__count
p1 = Person('Bob')
p2 = Person('Alice')
try:
print Person.__count
except AttributeError:
print 'attributeerror'
class Person(object):
__count = 0
def __init__(self, name):
Person.__count += 1
self.name = name
print Person.__count
p1 = Person('Bob')
p2 = Person('Alice')
try:
print Person.__count
except AttributeError:
print 'attributeerror'
2018-10-18
def count():
fs = []
for i in range(1, 4):
def f(x = i):
return x*x
fs.append(f)
return fs
f1, f2, f3 = count()
print f1(), f2(), f3()
fs = []
for i in range(1, 4):
def f(x = i):
return x*x
fs.append(f)
return fs
f1, f2, f3 = count()
print f1(), f2(), f3()
2018-10-18
import math
def is_sqr(x):
return math.sqrt(x)%1.0 == 0.0
print filter(is_sqr, range(1, 101))
def is_sqr(x):
return math.sqrt(x)%1.0 == 0.0
print filter(is_sqr, range(1, 101))
2018-10-17