列表[1,2,3,4,5],请使用map()函数输出[1,4,9,16,25],并使用列表推导式提取出大于10的数,最终输出[16,25]

列表[1,2,3,4,5],请使用map()函数输出[1,4,9,16,25],并使用列表推导式提取出大于10的数,最终输出[16,25]

def f(x):
    return x**2
 
 
res = map(f, [1, 2, 3, 4, 5])
print([i for i in res if i > 10])

python中生成随机整数、随机小数、0—1之间小数方法

import random
import numpy as np
 
a = random.randint(10,20)
res = np.random.randn(5)
ret = random.random()
print("正整数:"+str(a))
print("5个随机小数:"+str(res))
print("0-1随机小数:"+str(ret))

本文首发于Python黑洞网,博客园同步跟新

 

猜你喜欢

转载自www.cnblogs.com/pythonzhilian/p/12458091.html