影片378

程式碼

file = open("ascii.txt", "r+", encoding='utf8')
x = f.read()
print(x)
f.write("謝宸峰") #寫入字串
f.close() #謝宸峰關閉檔案r+讀增加append
print('f長度',len(x))
for i in x: #用迴圈印出每一個字元
    print(i)

截圖

程式碼

f = open("ascii.txt", "r+", encoding='utf8')
print("老師",f.name)
print("程式",f.mode)
print("關閉",f.closed)
f.write("謝宸峰")
line=f.read()
print("檔案字串長度",len(line))
f.close()
for i in line:
    print(i)

截圖

留言

這個網誌中的熱門文章

謝宸峰tkinter套件建立圖形使用者介面GUI=Graphical User Interface

謝宸峰Python 與JavaScript對照

謝宸峰VS code編輯HTML,CSS,JS俄羅斯方塊