开发者

Meaning of >> in print statement

开发者 https://www.devze.com 2023-02-01 18:44 出处:网络
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.

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

精彩评论

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