print ("hello world")
print ("hello Again")
print ("I like typing this.")
print ("This is fun.")
print ('Yay! Printing')
print ("I'd much rather you 'not'.")
print ('I "said" do not touch this.)
如果你看到类似如下的错误信息:
$ python ex/ex1.py
File "ex/ex1.py", line 3
print "I like typing this.
^
SyntaxError: EOL while scanning string literal
- 首先在命令行终端输入命令来运行 ex1.py 脚本。
- Python 告诉我们文件的第 3 行有一个错误。
- 然后这一行的内容被打印了出来。
- 然后 Python 打印出一个 ^ (井号,caret) 符号,用来指示出错的位置。 注意到少了一个 " (双引号,double-quote) 符号了吗?
- 最后,它打印出了一个“语法错误(SyntaxError)”告诉你究竟是什么样的错误。通常这些错误信息都非常难懂,不过你可以把错误信息的内容复制到搜索引擎里,然后你就能看到别人也遇到过这样的错误, 而且你也许能找到如何解决这个问题。
PS Python 3.0的新特性。print变为函数,必须加()。
加分习题
①让你的脚本再多打印一行。
①让你的脚本再多打印一行。
print ("Hello World!")
print ("Hello Again")
print ("I like typing this.")
print ("This is fun.")
print ('Yay! Printing.')
print ("I'd much rather you 'not'.")
print ('I "said" do not touch this.')
print ('让你的脚本再多打印一行')
在一行的起始位置放一个 ‘#’ (octothorpe) 符号。它的作用是什么?自己研究一下。
从现在开始,除非特别情况,我将不再解释每个习题的工作原理了。
#print ("Hello World!")
#print ("Hello Again")
#print ("I like typing this.")
#print ("This is fun.")
#print ('Yay! Printing.')
#print ("I'd much rather you 'not'.")
#print ('I "said" do not touch this.')