python3的话可以用这个
s1=['bob', 'about', 'Zoo', 'Credit']
print(s1.sort())
s1=['bob', 'about', 'Zoo', 'Credit']
print(s1.sort())
2020-03-18
3.0后版本 print(list(filter(is_sqr,[x for x in range(1,101)])))
2020-03-18
import math
def is_sqr(x):
return math.sqrt(x)-int(math.sqrt(x))==0.0
print filter(is_sqr,range(1,101))
这样也可以
利用math.sqrt(4)=2.0是小数的特点,直接判断真假
def is_sqr(x):
return math.sqrt(x)-int(math.sqrt(x))==0.0
print filter(is_sqr,range(1,101))
这样也可以
利用math.sqrt(4)=2.0是小数的特点,直接判断真假
2020-03-13
def count():
fs = []
for i in range(1,4):
def sum(x=i):
return x*x
fs.append(sum)
return fs
f1, f2, f3 = count()
print f1(), f2(), f3()
总结,内部函数可以调用外部变量,而外部函数不能调用内部变量
fs = []
for i in range(1,4):
def sum(x=i):
return x*x
fs.append(sum)
return fs
f1, f2, f3 = count()
print f1(), f2(), f3()
总结,内部函数可以调用外部变量,而外部函数不能调用内部变量
2020-03-06
print sorted(['bob', 'about', 'Zoo', 'Credit'], key=lambda x: x.title())
2020-03-06
def prod(x, y):
a = x*y
return a
print reduce(prod, [2, 4, 5, 7, 12])
a = x*y
return a
print reduce(prod, [2, 4, 5, 7, 12])
2020-03-06
def format_name(s):
return s.capitalize()
print map(format_name, ['adam', 'LISA', 'barT'])
return s.capitalize()
print map(format_name, ['adam', 'LISA', 'barT'])
2020-03-06
import math
def add(x, y, f):
return f(x) + f(y)
print add(25, 9,math.sqrt)
def add(x, y, f):
return f(x) + f(y)
print add(25, 9,math.sqrt)
2020-03-06