import math
def is_sqr(x):
a = math.sqrt(x)
if a == int(a):
return x
print filter(is_sqr, range(1, 101))
大家看看我的有没有创新
def is_sqr(x):
a = math.sqrt(x)
if a == int(a):
return x
print filter(is_sqr, range(1, 101))
大家看看我的有没有创新
2018-11-20
def format_name(s):
a = s.title()
return a
print map(format_name, ['adam', 'LISA', 'barT'])
a = s.title()
return a
print map(format_name, ['adam', 'LISA', 'barT'])
2018-11-20
Python 3 已经将reduce函数删除,如果要用的话需要调用functools 模块
并用lambda匿名函数实现如下:
from functools import reduce
print(reduce(lambda x,y:x*y, [2, 4, 5, 7, 12]))
并用lambda匿名函数实现如下:
from functools import reduce
print(reduce(lambda x,y:x*y, [2, 4, 5, 7, 12]))
2018-11-20
import json
class Students(object):
def read(self):
return r'["Tim","Bob","Alice"]'
s = Students()
print json.load(s)
class Students(object):
def read(self):
return r'["Tim","Bob","Alice"]'
s = Students()
print json.load(s)
2018-11-18
def count():
fs = []
def f(j):
def g():
return j*j
return g
for i in range(1, 4):
r=f(i)
fs.append(r)
return fs
f1, f2, f3 = count()
print f1(), f2(), f3()
也可以这样哦
fs = []
def f(j):
def g():
return j*j
return g
for i in range(1, 4):
r=f(i)
fs.append(r)
return fs
f1, f2, f3 = count()
print f1(), f2(), f3()
也可以这样哦
2018-11-18
def calc_prod(lst):
def lazy_prod():
return reduce (lambda x,y:x*y , lst)
return lazy_prod
f = calc_prod([1, 2, 3, 4])
print f()
def lazy_prod():
return reduce (lambda x,y:x*y , lst)
return lazy_prod
f = calc_prod([1, 2, 3, 4])
print f()
2018-11-09
有些人喜欢装逼,本来装饰器这一块就讲的不仔细,太概了,你看完python基础视频来看这个进阶,不去看看其他的 你觉得easy?
2018-11-08
在win命令中
可以执行https://img1.sycdn.imooc.com//5be3faa60001881e06110143.jpg
可以执行https://img1.sycdn.imooc.com//5be3faa60001881e06110143.jpg
2018-11-08
class Person(object):
def __init__(self, name, gender, **kw):
self.name=name
self.gender=gender
for k,v in kw.iteritems():
setattr(self,k,v)
p = Person('Bob', 'Male', age=18, course='Python')
print p.age
print p.course
def __init__(self, name, gender, **kw):
self.name=name
self.gender=gender
for k,v in kw.iteritems():
setattr(self,k,v)
p = Person('Bob', 'Male', age=18, course='Python')
print p.age
print p.course
2018-11-08
代码有错,在print 'call %s() in %fs' % (f.__name__, (t2 - t1))中的%fs 改为%f s,就是在f和s之间加一个空格
2018-11-03