python3 實用筆記 * 本篇資料來源為莫煩 python: https://morvanzhou.github.io/ python 文件讀寫 w 讀 r 寫 a 附加 (append) my_file = open( 'myfile.txt' , 'w' ) my_file.write( "XD" ) my_file.close file = open( 'myfile.txt' , 'r' ) content = file.read() content_arr = file.readlines() // 以 array 方式逐行儲存 print(content) 目前這樣容易會忘了關檔,這時候用 with 是個不錯的選擇 python tuple & list a_tuple = ( 1 , 2 , 3 , 4 ) another_tuple = 2 , 4 , 6 , 8 , 10 a_list = [ 1 , 2 , 3 , 4 , 5 ] a_list.sort(reverse= True ) print(a_tuple) # (1, 2, 3, 4) print(another_tuple) # (2, 4, 6, 8, 10) print(a_list) # [5, 4, 3, 2, 1] python dictionary dic = { 'key1' : 1 , 'key2' : 2 , 'key3' : 3 , 4 : 'haha' } dic2 = { 'pear' :{ 1 : 3 , 3 : 'a' }, 'orange' : '2017' } # 沒有順序 print(dic) # {'key3': 3, 'key2': 2, 'key1': 1, 4: 'haha'} pri