###### tags: `Python` # 第十一堂課-開啟檔案 ```python= file = open("data.txt", "r") #r:read(讀取) for n in file: print(n, end = "") file.close ``` :::spoiler 執行結果  ::: ```python= file = open("data.txt", "r") #r:read for n in file: n2 = n.strip() #strip()去除換行符號\n print(n2) file.close ``` :::spoiler 執行結果  ::: ```python= data = "abc:def:xyz" list = data.split(":") #split:分割 print(list) print(list[0]) ``` :::spoiler 執行結果  ::: ```python= file = open("member.txt", "r") for n in file: list = n.strip().split(",") print(list) file.close() ``` :::spoiler 執行結果  ::: ```python= file = open("member.txt", "r") name = input("帳號:") pwd = input("密碼:") chk = 0 for n in file: list = n.strip().split(",") if name == list[0] and pwd == list[1]: chk =1 if chk == 1: print("正確") else: print("登入失敗") file.close() ``` :::spoiler 執行結果  ::: ```python= file = open("member2.csv", "r") name = input("帳號:") pwd = input("密碼:") chk = 0 for n in file: list = n.strip().split(",") if name == list[0] and pwd == list[1]: chk =1 if chk == 1: print("正確") else: print("登入失敗") file.close() ``` :::spoiler 執行結果  :::
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up