1、測試數據
root@PC1:/home/test# ls test.py test.txt root@PC1:/home/test# cat test.txt ## 測試數據 w r s f z s d g z c w d z d g g z c e w root@PC1:/home/test# cat test.py fp = open("test.txt", "r") length = len(fp.readlines()) ## 將讀入文件轉化為列表, 然后統計列表的長度 print("length = ", length) ## 打印結果 fp.close() root@PC1:/home/test# python3 test.py length = 5
2、