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
def prod(x, y):
return x+y;
print reduce(prod, [2, 4, 5, 7, 12],3330)
return x+y;
print reduce(prod, [2, 4, 5, 7, 12],3330)
2016-06-05