#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: List[ pandas.Series ] 轉DataFrame技巧:正確理解row和column的關係,同 concat( List[ pandas.Series ], axis=1 ).T Python: List[ pandas.Series ] 轉DataFrame技巧:正確理解row和column的關係,同 concat( List[ pandas.Series ], axis=1 ).T](https://i1.wp.com/savingking.com.tw/wp-content/uploads/2025/04/20250422150133_0_1cfa94.png?quality=90&zoom=2&ssl=1&resize=350%2C233)


近期留言