print SyntaxError: invalid syntax错误的问题

        作为一门这么火的语言,作为一名码农,不学一下怎么能行呢,今天开始学习python之路。我看的资料是网上的《简明 Python 教程》Swaroop, C. H. 著,沈洁元  译,网址是http://sebug.net/paper/python/,才看一点不知道怎么样。还有一本就是《python基础教程》第二版,还在下载。

        刚写一行就遇到问题了,我擦咧 ,果断百度,于是看到了下面的解决方法。可能简明python教程这本书稍微老了点。- -!

>>>print"Hello World!"
File
"<stdin>", line 1
   
print"Hello World!"
                      
^
SyntaxError: invalid syntax
>>>

 

 

出错原因:

 

    python v3.0以后的版本中将v2.x版本的print 改为了print.

 

   所以此处调用print("Hello World!")则可成功。

print 的修改:

Old: print "The answer is", 2*2
New: print("The answer is", 2*2)
  
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)!

 

 

posted on 2012-09-24 18:21  W@SuperC  阅读(950)  评论(0)    收藏  举报

导航