串列[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黑洞網,博客園同步跟新
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/179269.html
標籤:Python
上一篇:20.python迭代器
下一篇:Python基礎資料型別
