列表[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黑洞网,博客园同步跟新

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。

 

 

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄