Python 2.7では、次の両方が同じことを行います
print("Hello, World!") # Prints "Hello, World!"
print "Hello, World!" # Prints "Hello, World!"
ただし、以下は
print("Hello,", "World!") # Prints the tuple: ("Hello,", "World!")
print "Hello,", "World!" # Prints the words "Hello, World!"
Python 3.xでは括弧print
は必須であり、本質的にそれを関数にしますが、2.7では両方とも異なる結果で機能します。print
Python 2.7では他に何を知っておくべきですか?
from __future__ import print_function
print
、実際には関数ではなく特別なステートメントです。これも、次のように使用できない理由です。タプルは作成さlambda x: print x
れ(expr)
ません(結果はexpr
)が、作成されることに注意してください,
。