林凱立python檔案file方法methods

f = open("ascii.txt", "r")
#林凱立開啟open檔案ascii.txt讀取模式r開啟之後要關閉
x = f.read()
f.close()
print("檔案長度", len(x))
print("列印內容",x)
f = open("ascii.txt", "r")
y = f.readlines() #輸出成列串,長度是列數
f.close()
print(y)
print("串列y的長度",len(y))
for i in range(len(y)): #迴圈跑i成0到y的長度
    print("第",i+1,"列",y[i])
f = open("ascii.txt", "a")#加入append()
f.write("林凱立")

留言

這個網誌中的熱門文章

林凱立產業分析認識軟體產業

林凱立投資學股利成長模型