开发者

Meaning of >> in print statement

I was wondering what does print >> dbfile, key mean in python. What is the >开发者_Go百科> supposed to do?


It should be noted that the >> syntax is specific to Python 2.x. In Python 3.x, that syntax goes away and code needs to be changed as follows:

print >>f, "Hello world"           # Python 2.x

print("Hello world", file=f)       # Python 3.x


This redirects print to a file (in this case, dbfile).

the >> is just a special syntax used for this.


See “The print statement” in the Python language reference. The object indicated must have a write method.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜