#Python TQC考題902 資料加總
f=open(“read.txt”,”r”,enconding=”utf-8″)
data=f.read()
L=[int(i) for i in data.split()]
print(sum(L))
f.close()

“””
read.txt的內容:
1 2 3 6 3
(加總=15)
“””

#多印一些資料,了解程式運作:
#read.txt內容: 1 4 2 3 (加總10)

#用.readline()也可以

#少encoding=”utf-8″ 也行

“””
TQC txt檔的資料為:
11 22 33 22 33 44 33 44 55 44 55 66 55 66 77
雖然簡單,但還是可能使用
.append(line.split())
做成list中還有list
“””








![為什麼 Python 要用 `max` 配合 `key=lambda`?從找最長文字的 Span 談起 ; #spans:list[dict] ; max(spans, key=lambda s: len(s.get(“text”, “”))) 為什麼 Python 要用 `max` 配合 `key=lambda`?從找最長文字的 Span 談起 ; #spans:list[dict] ; max(spans, key=lambda s: len(s.get(“text”, “”)))](https://i0.wp.com/savingking.com.tw/wp-content/uploads/2026/06/20260602132524_0_c45d06.png?quality=90&zoom=2&ssl=1&resize=350%2C233)



近期留言