这个循环呢,就是网fs中加入了三个函数,f1,f2,f3分别只想三个函数,如下所示。不改之前函数内容是[i*i,i*i,i*i],调用时,i=3;改之后是[m*m,m*m,m*m]调用时,m分别等于1,2,3。
count()
Out[24]: [<function __main__.f>, <function __main__.f>, <function __main__.f>]
count()
Out[24]: [<function __main__.f>, <function __main__.f>, <function __main__.f>]
2016-06-08
L = ['test',None,'','str',' ','END']
>>> def f(s):
... return s and len(s.strip())>0
...
>>> filter(f,L)
['test', 'str', 'END']
用调用函数的形式 ,可读性更高
>>> def f(s):
... return s and len(s.strip())>0
...
>>> filter(f,L)
['test', 'str', 'END']
用调用函数的形式 ,可读性更高
2016-06-08
L = ['test',None,'','str',' ','END']
>>> def f(s):
... return s and len(s.strip())>0
...
>>> filter(f,L)
['test', 'str', 'END']
用调用函数的形式,可读性更高
>>> def f(s):
... return s and len(s.strip())>0
...
>>> filter(f,L)
['test', 'str', 'END']
用调用函数的形式,可读性更高
2016-06-08
import math
def is_sqr(x):
return str(math.sqrt(x))[-1] == '0'
print filter(is_sqr, range(1, 101))
def is_sqr(x):
return str(math.sqrt(x))[-1] == '0'
print filter(is_sqr, range(1, 101))
2016-06-07
复习一下
def uplow(*x):
return [x[y][0].upper()+x[y][1:].lower() for y in range(0,len(x))]
print uplow('adam', 'LISA', 'barT')
def uplow(*x):
return [x[y][0].upper()+x[y][1:].lower() for y in range(0,len(x))]
print uplow('adam', 'LISA', 'barT')
2016-06-07
快速生成式:
a = ['adam', 'LISA', 'barT']
def uplow(x):
return [x[y][0].upper()+x[y][1:].lower() for y in range(0,len(x))]
print uplow(a)
map方法:
def format_name(s):
return s[0].upper()+s[1:].lower()
print map(format_name, ['adam', 'LISA', 'barT'])
a = ['adam', 'LISA', 'barT']
def uplow(x):
return [x[y][0].upper()+x[y][1:].lower() for y in range(0,len(x))]
print uplow(a)
map方法:
def format_name(s):
return s[0].upper()+s[1:].lower()
print map(format_name, ['adam', 'LISA', 'barT'])
2016-06-07
def calc_prod(lst):
def prod():
def f(x, y):
return x*y
return reduce(f, lst)
return prod
f = calc_prod([1, 2, 3, 4])
print f()
def prod():
def f(x, y):
return x*y
return reduce(f, lst)
return prod
f = calc_prod([1, 2, 3, 4])
print f()
2016-06-06
from os import path
print path.isdir(r'/data/webroot/resource/python')
print path.isfile(r'/data/webroot/resource/python/test.txt')
这个调用方式真新奇
print path.isdir(r'/data/webroot/resource/python')
print path.isfile(r'/data/webroot/resource/python/test.txt')
这个调用方式真新奇
2016-06-06
每次想调用模块里的函数要写那么长!假如某个人写的自定义函数放到包里面,每次调用就要写:
xuexiao.lurenjia.system.output.version1.myPrint("dajiahao")
xuexiao.lurenjia.system.output.version1.myPrint("wo lai ji suan yi xia")
xuexiao.lurenjia.system.output.version1.solveSum(x, y)
而C#, Java都是直接写myPrint(...),solveSum(...)就好了,python写这么长是不是很Stupid...
xuexiao.lurenjia.system.output.version1.myPrint("dajiahao")
xuexiao.lurenjia.system.output.version1.myPrint("wo lai ji suan yi xia")
xuexiao.lurenjia.system.output.version1.solveSum(x, y)
而C#, Java都是直接写myPrint(...),solveSum(...)就好了,python写这么长是不是很Stupid...
2016-06-06