右移运算符在 python print 语句中如何工作?
我见过有人将“print”与“>>”一起使用将内容写入文件:
In [7]: with open('text', 'w') as f:
...: print >> f, "Hello, world!"
...:
In [8]: !type text
Hello, world!
它是如何工作的?我什么时候应该使用它而不是仅仅使用“write”方法?
I've seen someone using "print" with ">>" to write stuffs into a file:
In [7]: with open('text', 'w') as f:
...: print >> f, "Hello, world!"
...:
In [8]: !type text
Hello, world!
How does it work? When should I use this instead of just using the "write" method?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
来自 https://docs.python.org/2/reference/ simple_stmts.html#the-print-statement
From https://docs.python.org/2/reference/simple_stmts.html#the-print-statement