Python 首頁 | Data Type | Function | 檔案處理 | 模組 |
參見 Python初學 模組
import random
import time arr1 = [] s = time.time() for i in range(int(1e+6)): arr1.append(i) print('took {} secs'.format(round(time.time() - s, 3))) s = time.time() arr2 = [i for i in range(int(1e+6))] print('took {} secs'.format(round(time.time() - s, 3)))
import random print(random.randint(1, 100))
import random as rm print(rm.randint(1, 100))
from random import function
from random import randint print(randint(1, 100))
f = open("test.txt", "r") f_list = f.readlines() print(f_list) f.close()
f.write()
f = open("test.txt", "w") f.write("Try to use file.write()\nHail HYDRA") f.close() f = open("test.txt", "r") words = f.read() print(words) f.close()