我见过有人使用"print"和">>"将东西写入文件:
In [7]: with open('text', 'w') as f: ...: print >> f, "Hello, world!" ...: In [8]: !type text Hello, world!
它是如何工作的?什么时候应该使用它而不是只使用"写"方法?
python grammar
grammar ×1
python ×1