这是为什么抱怨无效的语法?为什么这是无效的语法?
#! /usr/bin/python
recipients = []
recipients.append('[email protected]')
for recip in recipients:
print recip
我不断收到:
这是为什么抱怨无效的语法?为什么这是无效的语法?
#! /usr/bin/python
recipients = []
recipients.append('[email protected]')
for recip in recipients:
print recip
我不断收到:
如果它是Python 3,print
现在是一个函数。正确的语法是
print (recip)
在python 3中,print不再是一个语句,而是一个function。
Old: print "The answer is", 2*2
New: print("The answer is", 2*2)
更多蟒蛇3 print
功能:
Old: print x, # Trailing comma suppresses newline
New: print(x, end=" ") # Appends a space instead of a newline
Old: print # Prints a newline
New: print() # You must call the function!
Old: print >>sys.stderr, "fatal error"
New: print("fatal error", file=sys.stderr)
Old: print (x, y) # prints repr((x, y))
New: print((x, y)) # Not the same as print(x, y)!
重复:http://stackoverflow.com/questions/826948/python-syntax-error-on-print – 2009-12-07 20:04:47