[閒聊] 新發現print >>的用法

看板Python作者 (opiumeater)時間14年前 (2011/03/23 22:47), 編輯推噓0(002)
留言2則, 1人參與, 最新討論串1/3 (看更多)
今天才發現原來print可以這樣用: f = open('txt','w') for i in range(10): print >> f,i 我以前都會寫成 f = open('txt','w') a = map(str, range(10)) txt = '\n'.join(a) f.write(txt) f.close() 比較起來第一個好多了,跟大家分享。 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 123.193.213.133


03/23 23:48, , 2F
雖然我也常常 print 到 sys.stderr ...
03/23 23:48, 2F
文章代碼(AID): #1DYWWTYL (Python)
文章代碼(AID): #1DYWWTYL (Python)