PYTHON機器學習自學/自修 整理[00002] ~ 語言技術:Python Gossip(基本輸入輸出)
PYTHON機器學習自學/自修 整理[00002] ~ 語言技術:Python Gossip(基本輸入輸出)
code
import sys print('Hello!' +'!')#輸出(output) name = input('請輸入你的名稱:')#輸入(input) print('歡迎', name) name = input('請輸入檔名:') file = open(name, 'r', encoding='UTF-8')#檔案OPEN content = file.read()#檔案讀取 print(content) file.close() name = input('請輸入檔名:') file = open(name, 'r', encoding='UTF-8') while True: line = file.readline()#while迴圈單行讀取 if not line: break print(line, end='') file.close() name = input('請輸入檔名:') for line in open(name, 'r', encoding='UTF-8'): print(line, end='')#For迴圈單行讀取 file.close() name = input('請輸入檔名:') file = open(name, 'a+', encoding = 'UTF-8') file.writelines("print('Hello!' + '!')")#寫資訊到檔案中 file.close()